Showing the button when the VideoPlayer finishes
I am trying to make a final scene which starts with a short video. I've already managed to play the clip with the VideoPlayer GameObject, but the problem is that the button which is there as a part of the Canvas overlaps my video the whole time.
The button should be there to send you back to the main screen (basically to end and restart the game). Is there any way to make the button appear only when the video has finished playing? Or to hide the video when it stops playing? But in this case, how do I set my video to play in front of the button?
Add a CanvasGroup to the Canvas.
I'll use dummy variables for the canvas group and the video. Change these for your variables.
Start()
{
StartCoroutine(Play$$anonymous$$yVideo());
}
IENumerator Play$$anonymous$$yVideo()
{
cg.alpha=0;
cg.interactable=false;
video.Prepare();
video.Play();
While (video.IsPlaying())
{
yield return null;
}
cg.alpha=1;
cg.interactable=true;
}
$$anonymous$$ake sure you save everything before you run this, because if I've got the while loop wrong, you'll be stuck in an unbreakable loop.
I'm doing this from memory on my mobile so apologies if the code is not 100%.
Shouldn't it be
StartCoroutine(Play$$anonymous$$yVideo());
Because else it isn't going to work, is it?
Answer by NikitaDemidov · Apr 17, 2019 at 08:03 PM
You can change the alfa-channel in your Button/Video.
Many Objects have a standard color. If you write obj.color = new Color(obj.color.r,obj.color.g,obj.color.b,0f); You can't see the Object. obj.color = new Color(obj.color.r,obj.color.g,obj.color.b,1f); makes the Object appear.
If the button is an UI-Sprite try this:
void Start()
{
/*Starting the video(I don't know how to do this)*/
Invoke("ButtonOk" , videolenght);
}
void ButtonOk()
{
Button.GetComponent<Image>().color = new Color(0, 0, 0, 1f);
/*Add somthig like Button.getComponent<ButtonScr>().ButtonReady = true; Because else you still can press on the button even if it is invisible*/
}
Your answer
Follow this Question
Related Questions
2D toggle on/off button without UI? 0 Answers
Wait until video is over to show canvas,Wait until Video is over to show canvas 0 Answers
how to add bottom in 360 video? 0 Answers
How to move character with UI buttons? 0 Answers
Detecting a button click 1 Answer