public var Variable1;
public var Variable2;
public var Variable3;
//etc.
function Update()
{
if (Variable1 == true)
{
//blabla
}
if (Variable2 == true)
{
//blabla
}
if (Variable3 == true)
{
//blabla
}
//etc.
}
script2:
public var otherScript: script1;
private var X: int;
function Start ()
{
X = Random.Range(1,4)
otherScript.Variable'X' = true;
}
Of course this is not working because “Variable” is not part of script1.
But how can I do this? I know this must be possible. Something like converting int to string?
Script1 script1; //first part is name of script1 and second can be anything as it sets variable name so you can use later
script1 = gameObject.GetComponent<Script1>(); //this goes in start function and stores reference to script1 from gameobject (in this example it assumes script1 is in same gameobject)
script1.variable1 = 1; //sets variable 1 of script1 to 1
this is for c# and is one example to refference scripts
I’m not quite familiar with c# but what I mean is that in script2 the variable X is different everytime you start the script (it’s 1, 2 or 3).
When X = 1 in script2, then “Variable1” in script1 must be true.
When X = 2 in script2, then “Variable2” in script1 must be true.
etc.
So in script2 you actually need the code: otherScript.Variable1 = true; or
otherScript.Variable2 = true;
How can I put otherScript.Variable and X together?
otherScript.Variable+X or
otherScript.“Variable”+X or
otherScript.Variable+“X” or …