I apologize ahead of time for the bad coding etiquette…
I want to use this from my script “Rocket”
{
state = State.Dying;
audioSource.Stop();
audioSource.PlayOneShot(Dying);
shipExplode.Play();
Invoke("LoadFirstLevel", levelLoadDelay);
}```
In this which is my fuel gauge, to start the death/ dying sequence.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FuelDestroy : MonoBehaviour
{
public Text FuelText;
public Image FuelBar;
public float max_fuel = 100f;
public float cur_fuel = 100f;
public Rocket rocket;
// Start is called before the first frame update
void Start()
{
cur_fuel = max_fuel;
}
void decreaseFuel()
{
cur_fuel -= 100f;
float calc_fuel = cur_fuel / max_fuel;
SetFuel(calc_fuel);
}
void SetFuel(float fuel)
{
FuelBar.fillAmount = fuel;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
FuelBar.fillAmount -= 30f / max_fuel * Time.deltaTime;
}
if (max_fuel == 0f)
{
print(“Dead”);
}
}
}