How Do I Access And Change Variables In Different Scripts?

So I have script ‘x’ and script ‘y’. script ‘x’ has the variable ‘z’ and I want to access that variable from script y, so look at this for example:

Script X

var z = true;


argsdf
g
sdf
g
sdfhs
hton of code

Script Y

//here I want to access the variable 'z'


if (//variable 'z' == true)
{
    //do this command
}

so how would I do that?

You’d have to use GetComponent, here’s an example :

var A = GetComponent(ScriptX);

if(A.z == true){

//Do Something
}

OK, thanks!