Having an issue getting my script to do what I want.

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”);
}
}
}

  1. Hey, thanks for making an effort. But use the one in the red circle for big blocks of code in the future:
    6193497--679266--upload_2020-8-11_17-11-5.png

  2. To use the method from the rocket script from the FuelDestroy script all you need to do is this: rocket.StartDeathSequence(). It seems like you got the hard part out off the way already (it looks like?), which is getting the reference to the Rocket object. Just make sure you have dragged your Rocket object into the inspector for the FuelDestroy object or you will get an error when you try to run this code.

Sorry for the misuse there, I am very new to coding and I appreciate the input thank you very much.