//private void ChangeGunPosition() //{ // Vector3 horizontalOffset = new Vector3(0.5f, 0, 0); // Vector3 verticalOffset = new Vector3(0, 0.75f, 0); // if (Input.GetAxisRaw("Horizontal") != 0) // { // if (Input.GetAxisRaw("Horizontal") == -1) // { // if(Input.GetAxisRaw("Vertical") == 1) // { // transform.position = // playerTransform.position + (horizontalOffset * -1) + (verticalOffset * 0.5f); // } // else // transform.position = playerTransform.position + (horizontalOffset * -1); // } // if (Input.GetAxisRaw("Horizontal") == 1) // { // if (Input.GetAxisRaw("Vertical") == 1) // { // transform.position = // playerTransform.position + horizontalOffset + (verticalOffset * 0.5f); // } // else // transform.position = playerTransform.position + horizontalOffset; // } // } // else if(Input.GetAxisRaw("Vertical") == 1) // { // transform.position = playerTransform.position + verticalOffset; // } //} private void HandleShootingInput() { if (Input.GetButton("Action") && timeSinceLastBullet >= timeBetweenBulletsInSeconds) { timeSinceLastBullet = 0; //Shoot a bullet Vector2 directionToFire = GetDirectionToFire(); //Create new water bullet, then set speed WaterObject newBullet = Instantiate(bullet, transform.position, transform.rotation); //Set the speed of the water bullet Rigidbody2D waterObjectRigidbody = newBullet.GetComponent <Rigidbody2D>(); waterObjectRigidbody.velocity = (directionToFire * bulletSpeed); } timeSinceLastBullet += Time.deltaTime; }
void ShootGun() { if (Input.GetButton("Shoot") && cooldownTimeRemaining <= 0) { gunPointingDirection = transform.position - transform.parent.position; //Create new water bullet WaterObject newBullet = Instantiate(bullet, transform.position, transform.rotation); //Set the speed of the water bullet Rigidbody2D waterObjectRigidbody = newBullet.GetComponent <Rigidbody2D>(); waterObjectRigidbody.velocity = (gunPointingDirection.normalized * bulletSpeed); //Set cooldown cooldownTimeRemaining = gunCooldownTime; } }
void HandleShooting() { //Get raw input axese float horizontalInput = Input.GetAxisRaw("Horizontal"); float verticalInput = Input.GetAxisRaw("Vertical"); //Get total 8-way input direction Vector2 inputDirection = new Vector2(horizontalInput, verticalInput); Vector2 fireVector = GetDirectionalFireVector(inputDirection); if (inputDirection != Vector2.zero) { //Create new water bullet, then set speed WaterObject newBullet = Instantiate(bullet, transform.position, transform.rotation); Rigidbody2D bulletRigidbody = newBullet.GetComponent <Rigidbody2D>(); //bulletRigidbody.velocity = inputDirection * (bulletSpeed * directionalMagnitudeChange) ; } }
private void ShootInput() { //Cooldown timer goes down cooldownTimeRemaining += Time.deltaTime * -1; if (Input.GetButton("Shoot") && cooldownTimeRemaining <= 0) { //Create new water bullet WaterObject newBullet = Instantiate(bullet, transform.position, transform.rotation); //Set the speed of the water bullet Rigidbody2D waterObjectRigidbody = newBullet.GetComponent <Rigidbody2D>(); waterObjectRigidbody.velocity = (offsetVector.normalized * bulletSpeed); //Set cooldown cooldownTimeRemaining = gunCooldownTime; } }
private void SetUpWater() { //sizeZ = 150; //sizeX = 150; // Mesh for the map var mesh = new Mesh(); // Setting vertices var vertices = new List <Vector3>(Settings.WaterVertices); // Generating indices var indices = new List <int>(); for (int z = 0; z < sizeZ; z++) { for (int x = 0; x < sizeX; x++) { // Fetching indices for the current square int v1 = x + (z * (sizeX + 1)); int v2 = x + 1 + (z * (sizeX + 1)); int v3 = x + ((z + 1) * (sizeX + 1)); int v4 = x + 1 + ((z + 1) * (sizeX + 1)); // Saving them in the right order indices.AddRange(new[] { v3, v2, v1, v3, v4, v2 }); } } // Finilizing mesh mesh.SetVertices(vertices); //Назначаем вершины mesh.SetTriangles(indices, 0); //Назначаем треугольники - индексы вершин mesh.uv = Settings.WaterUVs; mesh.RecalculateBounds(); //Постройка меша mesh.RecalculateNormals(); //Постройка меша // Setting mesh to mesh renderers WaterObject.GetComponent <MeshFilter>().mesh = mesh; // Creating collider WaterObject.gameObject.AddComponent <MeshCollider>(); WaterObject.AddComponent <WaterBasic>(); WaterObject.transform.Translate(Vector3.up * Settings.WaterHeight); }
void Start() { //check if person object exists and fetch collider if (PersonObject != null) { PersonCollider = PersonObject.GetComponent <Collider>(); } //check if water object exists and fetch collider and audio source if (WaterObject != null) { WaterCollider = WaterObject.GetComponent <Collider>(); WaterSource = WaterObject.GetComponent <AudioSource>(); } //check for the existance of a water particle emitter and fetch audio source if (WaterfallObject != null) { WaterFallSource = WaterfallObject.GetComponent <AudioSource>(); } }
private void HandleShootingInput() { //Get horizontal input float horizontalInput = Input.GetAxisRaw("Horizontal"); if (Input.GetButtonDown("Action")) { //Get vert input float verticalInput = Input.GetAxisRaw("Vertical"); //Shoot even when standing still if (horizontalInput == 0 && verticalInput == 0) { horizontalInput = facingDirection; } //Get total 8-way input direction Vector2 inputDirection = new Vector2(horizontalInput, verticalInput); //Get player movement speed Vector2 playerVelocity = GameObject.Find("Player").GetComponent <Rigidbody2D>().velocity; //Create new water bullet WaterObject newWaterObject = Instantiate(waterObject, transform.position, transform.rotation); //Set the speed of the water bullet Rigidbody2D waterObjectRigidbody = newWaterObject.GetComponent <Rigidbody2D>(); waterObjectRigidbody.velocity = (inputDirection * fireSpeed) + new Vector2(playerVelocity.x, 0); //IMPORTANT NOTE: Shots need to be fired w/ different velocities depending // on the direction they are travelling. ???? i think } facingDirection = horizontalInput; }