UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Separated Jetpack system with spacebar"
public class JetpackSystem : MonoBehaviour { public float jetpackForce = 10f; public float jetpackFuel = 100f; public float fuelConsumptionRate = 1f; private Rigidbody rb; private bool isJetpacking; void Start() { rb = GetComponent<Rigidbody>(); } void Update() { if (Input.GetKeyDown(KeyCode.Space) && jetpackFuel > 0) { isJetpacking = true; } if (Input.GetKeyUp(KeyCode.Space) || jetpackFuel <= 0) { isJetpacking = false; } } void FixedUpdate() { if (isJetpacking) { rb.AddForce(Vector3.up * jetpackForce, ForceMode.Acceleration); jetpackFuel -= fuelConsumptionRate * Time.fixedDeltaTime; } } }