How do i create a time delay before the button appears unity

331 Views Asked by At

I am creating an interactive video using Unity/C#. I am doing this using scenes and buttons that when clicked, go to the next scene or back. However, I want the buttons to appear once the video is finished. Is there any way I can add a delay to the buttons before they appear in the scene when playing?

2

There are 2 best solutions below

1
Jaimin On BEST ANSWER

For time delay you could use coroutines. Check it out here There is options like waitforseconds so you can delay your button apperance. here is sample code

private IEnumerator ShowBtn()
{
    yield return new WaitWhile(() => videoplayer.isPlaying);
    // show visibility of your button
}

And when you play video call this function like this

StartCoroutine(ShowBtn());
0
PotSkill On

This should do the trick. isPlaying.

A simple script would look like this.

if(videoplayer.isPlaying == false && videoWasPlayed == true){
  btn.active = true;
  videoWasPlayed = false;
}

videoWasPlayed is used to check if the video was ever played. This would need to be set to true when the video is played.