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

Time:10-19

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?

CodePudding user response:

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.

CodePudding user response:

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());
  • Related