Author Topic: What are the best practices to make widgets appear and disappear during runtime?  (Read 3024 times)

lazlo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Say I have tooltips, windows, or other components that will open / close during runtime (be it on hover, on click, etc.).

What are the best practices to do so?

Ideally, my objectives are:
  • The GameObject would stay Active so it can be interacted with properly without an update frame.
  • The widget would be visible (active, enabled, and alpha 1) while in the editor, but not by default while playing.
  • The colliders would stop to work when the widget is hidden (I'm guessing alpha 0 on the parent won't work for this).
  • Tweens could be used (like a tween alpha) for a smooth transition.

Is that possible? If so, how?

For sake of asking a clearer question, how would I fill, for example, this code:

  1. public class TogglableWidget : MonoBehaviour
  2. {
  3.         public void Start()
  4.         {
  5.                 // Probably hide it?
  6.         }
  7.  
  8.         public void Open()
  9.         {
  10.                 // Make it visible and functional.
  11.         }
  12.  
  13.         public void Close()
  14.         {
  15.                 // Make it invisible and eventless.
  16.         }
  17. }
  18.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
This seems like an overly generic question for me to answer, to be honest.

I will say this though: setting alpha to 0 will effectively make the widget invisible to events.