My void not work... why ?

Hi guys ! I’ve created this script

// Use this for initialization
void Start () 
{
	instance = this;
	NumDoor = 0;

}

// Update is called once per frame
void Update () {
	if (NumDoor >= 1) 
	{
		BigDoor.Play("BigDoor 001");
	}

}

public void OpenDoor ()
{
	NumDoor = 0;

	if (NumDoor >= 1) 
	{
		BigDoor.Play("BigDoor 001");
	}
}

}

For what reason if i active the code in the Update void it work very well, but if i clean the update and i create my void ( OpenDoor ) it doesent work ?
Thank you !

Ps: Sorry for my english.

Hey @Cervelx!

I don’t really get your question, but I think you mean your OpenDoor() function doesn’t work when you put in it the Update()?
First of all, why do you set the NumDoor = 0; in the OpenDoor() function? It is already set to 0 in Start().
If you set it every frame in Update(), it will ‘never’ change. But maybe it’s on purpose?
Second, do you want to have the OpenDoor() function called every frame? Should it be in the Update() at all?
Last but not least, if you delete the NumDoor = 0; (line 20) in the OpenDoor() and put it in the Update() function, it will be the same as you have in Update() now, so:

void Start ()
{
   instance = this;
   NumDoor = 0;
}

void Update()
{
     OpenDoor();
}


public void OpenDoor()
{
    if (NumDoor >= 1)
     {
          BigDoor.Play("BigDoor 001");
     }
}

If I’m totally wrong, please try to explain what exactly the problem is :slight_smile:

I would try to rephrase what you said because I can’t really tell what you want but…

// This function is a Unity function and is called every frame. 
// So each second or more this function is being called and
// checking the NumDoor variable
 void Update () {
     if (NumDoor >= 1) 
     {
         BigDoor.Play("BigDoor 001");
     }
 
 }

 // From what I can see, this function is never being called by you.
 // Also you set NumDoor to 0, how can NumDoor ever be >= 1 
 // if you just set it to 0. The Play() code will never execute as the code is written
 public void OpenDoor ()
 {
     NumDoor = 0;
     if (NumDoor >= 1) 
     {
         BigDoor.Play("BigDoor 001");
     }
 }

sorry another question, if i dont want that OpenDoor is called every frame, but just one time to play the animation 1 time, what is the way ?