Deactivating a function?

Hello. From another script, how can I deactivate a function (like the one below, this is part of a script) without deactivating the entire script? Thanks.

function Update() {
if (Life <= 0){
	Application.LoadLevel("Over"); 
}}

Just script it:

var DoNotLoadLevel = false;
function Update()
{
if (DoNotLoadLevel == false Life <= 0)
{
Application.LoadLevel(“Over”);
}
}

then elsewhere in your code:
var myScript = GetComponent… //or however you get it
myScript.DoNotLoadLevel = true;

This is another script

function Awake() {
    startTime = Time.time;
    Stats.lives == false;
}

and this is the script with the “Load Level” thing. When I put the 1st script into the scene, the function in the second script is still going on…

var lives = true;

function Update() {
if (lives == true  Life <= 0){
	Application.LoadLevel("Over");
}}

First, this doesn’t assign Stats.lives to the value false because you used two equal signs instead of one.

Second, you didn’t add the cross-script code FizixMan recommended. As a result, in Script2 you check the value of Script2.lives rather than the value of Script1.Stats.lives (what you intended).

Do you realize having two variables with the same name (singular vs plural) and different meanings is confusing? Also, I could interpret lives to mean, “The player lives (true/false)?” or “The player has N lives”. In this case that part is at least clear since you’re comparing it to true, but since you didn’t post the initialization of Life, I can only guess at what that means. If, for examples, lives was replaced by isAlive and Life were replaced by healthPercent the meaning (and format) of the variables becomes much clearer. Just a tip. :slight_smile:

I removed one of the equal signs and I added this to script 1 (“Stats”) but it still isnt working, what am I doing wrong this time(“Timed” is the name of the second script)?

var myScript = GetComponent(Timed);

Anyone?

Nevermind. I just had to make it a static var.