| 123456789101112131415161718192021222324252627282930313233 |
- using UnityEngine;
- using UnityEngine.InputSystem;
- using static UnityEngine.InputSystem.DefaultInputActions;
- public class RocketController : MonoBehaviour
- {
- public RocketDataScript rocketData;
-
- private InputAction jumpAction;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
- jumpAction = InputSystem.actions.FindAction("Jump");
- }
- // Update is called once per frame
- void Update()
- {
- if (jumpAction.IsPressed())
- Thrust();
- }
- private void Thrust()
- {
- if (rocketData.Fuel > 0)
- {
- var rb = GetComponent<Rigidbody>();
- rb.AddForce(rocketData.Force * Time.deltaTime * transform.up);
- rocketData.AddFuel(-1 * Time.deltaTime);
- }
- }
- }
|