Could anyone help me? I need some delay before “GameObject.Find(“FadeGameObject”).GetComponent(). BeginFade(1);”
but I can’t use coroutine. And is it OK what I use before Application.LoadLevel? It works but I am not sure that it a good way ( I am not a programmer)
void Update ()
{
if (youWin)
{
GameObject.Find("FadeGameObject").GetComponent<Fading>(). BeginFade(1);
// .. increment a timer to count up to restarting.
restartTimer += Time.deltaTime;
// .. if it reaches the restart delay...
if (restartTimer >= timeDelay)
{
Application.LoadLevel(nextLevel);
}
}
}
You can use code before Application.LoadLevel(), there’s nothing wrong with that. Also coroutines work fine, not sure why you say you can’t use them. Anyway, if you want a delay before fading, then you can use the timer that is already present in the function.
void Update ()
{
if (youWin)
{
// .. increment a timer to count up to restarting.
restartTimer += Time.deltaTime;
// .. if it reaches the restart delay...
if (restartTimer >= timeDelay)
{
// might want add a check here, so BeginFade gets called only once. example:
if (GameObject.Find("FadeGameObject").GetComponent<Fading>().IsFading == false){
GameObject.Find("FadeGameObject").GetComponent<Fading>().BeginFade(1);
}
}
if (restartTimer >= timeDelay + 1f) // Replace 1f for the duration of the fade
{
Application.LoadLevel(nextLevel);
}
}
}
I have just found the way to use coroutine but anyway thank you for the answer. Frankly speaking I did not understand your check code, what is “isFading” and why should it be “false”? It does not work for me or I do something wrong.
And I heard that using GetComponent within void update is not a good idea and one should store it in a variable in Start or Awake. What do you thing about it?