- Home /
Question by
fadilRaditya · Jul 19, 2012 at 05:12 PM ·
variable
can i change a variable from other js?
var trackError : int = 0;
function OnTriggerEnter(other : Collider){
if(other.tag == "Player"){
Application.LoadLevel(0);
trackError=trackError+1;
print(trackError);
}
}
why always print 1? second question can i have 2 js and link it each other ? how it works and how to get the variable?
Comment
Can you please format your code so we can understand it? You can use the 'code' button after you select your code to format it.
Answer by Meltdown · Jul 19, 2012 at 06:41 PM
Its printing 1 because you are loading the level from scratch. If you wish to store a persistent value use PlayerPrefs
Or set DontDestroyOnLoad - see http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613074418im_/https://answers.unity.com/themes/thub/images/avi.jpg)