Search Unity

[GUI Appear] How to make a Button Appear?

Discussion in 'UGUI & TextMesh Pro' started by HeHeHaHa306, Mar 15, 2017.

  1. HeHeHaHa306

    HeHeHaHa306

    Joined:
    Feb 10, 2017
    Posts:
    24
    Hi Guys,

    I just create a VR APP for running a 360 video on my phone with google cardboard SDK but need to do some

    trigger for that .

    so my aims is when I open the app and the video will be Autoplay when its start, 3mins later (the end of the video), there are 2 button (I made it already its a 3D Cube) appear for the viewer and now my question is how to make it appear?

    Basiclly, my idea is make a timer that count to 3 mins and make the button appear. Is it right?

    btw, does anyone can give me some help about this? I don't even know how to create a timer, thank you!

    Have a good day
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    to wait 3 minutes you can use a coroutine:
    Code (CSharp):
    1. // somewhere when you start the video (inside a MonoBehaviour)
    2. this.StartCoroutine(WaitAndShowButtons());
    3.  
    4. // coroutine function
    5. System.Collections.IEnumerator WaitAndShowButtons()
    6. {
    7.     yield return new WaitForSeconds(3 * 60); // wait 3 minutes
    8.  
    9.     // show buttons here
    10. }
    If your button is just a UI-Image you can use the CrossFadeAlpha() method of it to fade it in.
    alternately you can also adjust the alpha inside a coroutine with a loop...

    PS: code not tested
     
  3. HeHeHaHa306

    HeHeHaHa306

    Joined:
    Feb 10, 2017
    Posts:
    24
    Thank you so much Hosnkobf !

    one more question, what should i use this code in? should I make it in my button ? my button is a 3D button , thank you!
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    probably not in the button because maybe you have the buttons inactive until you show them. This would be better for performance I guess, but when a component is inactive or disabled no coroutines can be started on that component (AFAIK).
    I would do it in a kind of manager component which is responsible for showing the video as well as the buttons. The logic of these two kind of relate to each other so I think it would be a good idea to put it in the same place.
     
  5. HeHeHaHa306

    HeHeHaHa306

    Joined:
    Feb 10, 2017
    Posts:
    24
    Thank you very much for your help Hosnkobf :)