How to reference a variable from a different script?

So, after doing some Googling this, I came across many Unity-answers pages about this, however I’m not sure if I’m looking to do something different than what I think I am, or If I’m just not comprehending this. I have a ‘Vitals’ Script. in the script I have two variables, ‘curHealth’ and ‘maxHealth’. I have another script called ‘LevelUp’. This script only holds three variables: ‘curEXP’ and ‘maxEXP’ and ‘PlayerLevel’. I have an ‘if’ statement setup to add 1 to the PlayerLevel variable. I’d also like to add 10 to the maxHealth variable in the ‘Vitals’ script. I’m not sure how to go about specifying the variable from the other script. I’m also using C#, so replies using JavaScript may seem foreign. Thanks for your help, ~~Matt

Matt, as other members mentioned where your scripts are is important. If the scripts are in the same object do so like this:

(IN SCRIPT 1)

public class SCRIPT1NAME : MonoBehaviour{

public SCRIPT2NAME myScriptReference;

void Start()

{
myscriptReference=GetComponent(SCRIPT2NAME);
}

(THEN TO REFERENCE THE VARIABLE OF SCRIPT 2 IN SCRIPT 1)

void myMethod()

{
myScriptReference.SCRIPT2VARIABLE;
}

}
if the Script two is attached to a different game object you will need one of the following:

GameObject.Find(“GAME OBJECT NAME WHERE SCRIPT 2 IS”).GetComponent();

or

GameObject.FindGameObjectWithTag(“TAG APPLIED TO GAME OBJECT WHERE SCRIPT 2 IS ATTACHED”).GetComponent<(SCRIPT 2 NAME)>();