- Home /
accessing a function?
Hello. I am trying to use a script to de-activate a function in another script.
This is the function I want to de-activate (the script is named "Stats")
var lives = true;
function Update() { if (lives == true && Life <= 0){ Application.LoadLevel("Over"); }}
and this is the script I am trying to use to set "Lives" to false.
function Awake() {
Stats.lives = false;
}
It is not working, what is wrong?
Answer by Johnathan · Dec 05, 2010 at 05:05 AM
I think all you need to do is use a static variable. Your first script should read Static var lives = true; A variable has to be static if you want to change it in a different script.
That seems to be the way Unity is built up yes. Statics and Singletons. Just don't forget you can use acces modifiers in C# if you ever use it, great tool for permissions. Similarly get{}set{} constructs for read/write permissions