basic js question..

Hi all…

maybe an Unity specific question:

How can i call and change a variable contained into another script… for instance:

script1:

function Update(){
var elevate = false;
}

script2:

function OnTriggerEnter(){
"here some kind of event that makes "elevate" (from script1) var changes to true".

some tips to achieve it?..

thank you!.

Script 2 should be something like this;

var varName:Script1Name //Filename of the first script here, like CameraSystem or HeadLookController etc.

function Update(){

    varName.VariableYouWantToChange += 1;

//all the variables and functions will be available to use after the . on the variable you defined as the first script

}

Does the variable have to be declared outside of function Update() to be visible to another script? I’m fairly new to scripting, too, so I’m just jumping in on the thread. Thanks!

thanks mortiis, i´d know that was pretty simple to do it…

tool55, i guess must be a global var, so then you drag and drop the called script into the inspector so the result will connect both. But if you don´t want to do that, just to code, i guess declaring the var inside the function will not be a problem (i guess)…

Try not to declare a variable inside an Update(). It wont cost you much, but its just one more thing… If you need to, declare it in a Start(), Awake(), or use a doOnce variable.

taking it in mind … thanks !