I have a boost script for my game that is suppose to act similar to the boost ability seen in racing games like burnout and hydro thunder where the player can hold down the boost button until the boost gauge depletes. I have basically replicated this but for some reason it only works in the unity editor, when running in the game build it only lasts for a slit second.
here’s the script:
[RequireComponent(typeof(AudioSource))]
public class NitroPlayer1 : MonoBehaviour {
public GameObject leftflames;
public GameObject rightflames;
public AudioClip activateSound;
AudioSource audioSource;
public GameObject vehicle;
static float remainingNitrous = 30;
static float MaxNitroCapacity = 30;
public bool CanRefill = false;
public Rigidbody rb;
static float thrust = 50000;
// Use this for initialization
void Start () {
audioSource = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1")){
if(remainingNitrous > 0){
leftflames.gameObject.SetActive(true);
rightflames.gameObject.SetActive(true);
}
}
if (Input.GetButtonUp("Fire1")){
leftflames.gameObject.SetActive(false);
rightflames.gameObject.SetActive(false);
}
if (remainingNitrous == 0){
leftflames.gameObject.SetActive(false);
rightflames.gameObject.SetActive(false);
}
if (Input.GetButtonUp("Fire1")){
if (remainingNitrous > 0){
CanRefill = true;
}
}
if(Input.GetButtonUp("Fire1")){
if(remainingNitrous == 0){
CanRefill = true;
}
}
if (remainingNitrous == MaxNitroCapacity){
CanRefill = false;
}
if (CanRefill){
remainingNitrous +=1;
}
if (Input.GetButtonDown("Fire1")){
if (remainingNitrous > 0){
audioSource.PlayOneShot(activateSound, 0.7F);
}
}
if (Input.GetButton ("Fire1")){
if (remainingNitrous > 0){
Nitrous();
}
}
}
void Nitrous(){
rb.AddForce(transform.forward * thrust);
remainingNitrous -= 1;
}
}
the player’s max boost capacity is 30.