RocketController.cs 827 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. using UnityEngine.InputSystem;
  3. using static UnityEngine.InputSystem.DefaultInputActions;
  4. public class RocketController : MonoBehaviour
  5. {
  6. public RocketDataScript rocketData;
  7. private InputAction jumpAction;
  8. // Start is called once before the first execution of Update after the MonoBehaviour is created
  9. void Start()
  10. {
  11. jumpAction = InputSystem.actions.FindAction("Jump");
  12. }
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. if (jumpAction.IsPressed())
  17. Thrust();
  18. }
  19. private void Thrust()
  20. {
  21. if (rocketData.Fuel > 0)
  22. {
  23. var rb = GetComponent<Rigidbody>();
  24. rb.AddForce(rocketData.Force * Time.deltaTime * transform.up);
  25. rocketData.AddFuel(-1 * Time.deltaTime);
  26. }
  27. }
  28. }