// Update is called once per frame void FixedUpdate() { // Has the D key been pressed? if (Input.GetKey(KeyCode.D) && particle.rotation >= -maxRotation) { // If yes, then add torque in the right direction particle.ApplyTorque(new Vector2(-thrustSpeed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y)); } // Has the A key been pressed? else if (Input.GetKey(KeyCode.A) && particle.rotation <= maxRotation) { // If yes, then add torque in the left direction particle.ApplyTorque(new Vector2(thrustSpeed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y)); } // Has the lander reached it's maximum rotation? else if ((particle.rotation > maxRotation || particle.rotation < -maxRotation) && GameManager.manager.isRunning) { // If yes, then stop it in place particle.angularVelocity = 0; } // Has the W key been pressed and there is enough fuel? if (Input.GetKey(KeyCode.W) && fuelLeft > 0 && GameManager.manager.isRunning) { // If yes, then subtract fuel fuelLeft -= amountOfFuelLostPerBurn; // Add a force in the upward direction of the lander particle.AddForce(speed * transform.up); // Enable flame particle effect flame.SetActive(true); } else { // If no, then disable the flame particle effect flame.SetActive(false); } // Has the S key been pressed and there is enough fuel? if (Input.GetKey(KeyCode.S) && fuelLeft > 0) { // If yes, then subtract the fuel fuelLeft -= amountOfFuelLostPerBurn; // Add a force in the downward direction of the lander particle.AddForce(speed * -transform.up); } }
// Update is called once per frame void Update() { // Has the D key been pressed? if (Input.GetKey(KeyCode.D)) { // If yes, then add a force and torque in the right direction (opposite direction for torque) particle.AddForce(new Vector2(speed, 0)); particle.ApplyTorque(new Vector2(-speed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y)); } // Has the A key been pressed? if (Input.GetKey(KeyCode.A)) { // If yes, then add a force and torque in the left direction (opposite direction for torque) particle.AddForce(new Vector2(-speed, 0)); particle.ApplyTorque(new Vector2(speed, 0), new Vector2(0, transform.position.y + particle.boxDimensions.y)); } }