I have two scripts: script1: Code (JavaScript): 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: Code (JavaScript): 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?
in second script: Code (CSharp): 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
Thanks for reply. 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: Code (JavaScript): otherScript.Variable1 = true; or Code (JavaScript): otherScript.Variable2 = true; How can I put otherScript.Variable and X together? otherScript.Variable+X or otherScript."Variable"+X or otherScript.Variable+"X" or ... I know there must be a way.
oh Code (CSharp): if(x == 1) script1.variable1 = true; else if (x == 2) script1.variable2 = true; else script1.variable3 = true;