/// <summary> /// Deplot the powerup, if possible /// </summary> public void FirePowerUp() { if (PowerUp) { PowerUp.Fire(); PowerUp = null; GetComponent <AudioSource>().PlayOneShot(DeployPowerUpSound); } }
/// <summary> /// Move the tank and fire if necessary. /// </summary> internal void Update() { // Accelerate if necessary var forward = DeadZone(Input.GetAxis(VerticalAxis)); var targetSpeed = forward * ForwardSpeed; var forwardSpeed = Vector2.Dot(tankRb.velocity, transform.up); var forceMagnitude = Acceleration * (targetSpeed - forwardSpeed); tankRb.AddRelativeForce(forceMagnitude * Vector2.up); // Apply directional damping var right = transform.right; var damping = Vector2.Dot(right, tankRb.velocity); tankRb.AddForce(-damping * right); // Apply steering control if we aren't spinning out of control if (tankRb.angularVelocity < RotationSpeed * 0.5f) { tankRb.angularVelocity = 0; tankRb.rotation += DeadZone(Input.GetAxis(HorizontalAxis)) * Time.deltaTime * RotationSpeed; } // Fire if (Input.GetKeyDown(FireButton)) { FireProjectileIfPossible(); } // Deploy power up if (PowerUp != null && Input.GetKeyDown(PowerUpButton)) { Debug.Log("Ppowerup"); PowerUp.Fire(); PowerUp = null; GetComponent <AudioSource>().PlayOneShot(DeployPowerUpSound); } }