Hello everyone, I have a jetpack script that I made and am having a few issues, for starters my gameplay is a 3rd person platformer that has an open world feature. In one of my worlds you are on the moon and can use the jetpack to jet around, only I don’t want the player to be able to jet into the air forever so I would like to add a “gas” feature with a visible bar in the lower middle of the screen.
(When player holds F button jetpack is activated LIFT UP, when player is not grounded jet animations are activated, when player is grounded jet animations are de-activated)
This is where my issue is, does anyone have a good way of doing this with my script? Thanks!
Script:
using UnityEngine;
using System.Collections;
public class JetPack : MonoBehaviour {
public float JetPackForce;
public float startTime = 3.5f;
public GameObject player;
public GameObject Rocket1;
public GameObject Rocket2;
Animator anim;
void Start(){
anim = GetComponent<Animator>();
}
void FixedUpdate () {
if (Input.GetKey (KeyCode.F)) {
Rocket1.SetActive(true);
Rocket2.SetActive(true);
startTime -= Time.deltaTime;
player.rigidbody.AddForce(new Vector3(0.0f, 1.0f, 0.0f) * JetPackForce);
}
if (startTime <= 0.0f) {
player.rigidbody.velocity = Vector3.down * Time.smoothDeltaTime;
startTime = 3.5f;
}
if(anim.GetBool("Grounded")) {
Rocket1.SetActive(false);
Rocket2.SetActive(false);
}
}
}