How do you get a variable from another script?

I want to be able to pull a variable from one script to another one, i’m not sure how…

void Update(){ if (Input.GetMouseButtonDown (0)) { if (count <= 0) { NoAmmo.Play (); } if (count > 0) { Gun.Play (); count = count - 1; SetCountText (); } } }
i want to be able to get the count component, as it decides if an object will be removed or not

At the top of the script, define a: public int (or float) count;

Then, in a different script you need to get access to this script (I don’t know the name of your class):
private GunScript gunScript = otherGameobject.getComponent();
Debug.Log(gunScript.count);

otherGameObject will need to be gotten somehow in your 2nd script.
You can do it by defining a public gameObject like this:

// Assign this in the inspector
public GameObject otherGameObject;

Then drag your object with the script you want variables from onto the 2nd object in the inspector

Or you can also get GameObject if you tag your first script with a Tag called “SomeTag”
then in the second script:

private GameObject otherGameObject;

void Start()
{
       otherGameObject = GameObject.FindWithTag("SomeTag");
}