Search Unity

Making a panel active / inactive

Discussion in 'UGUI & TextMesh Pro' started by Fabkins, Aug 31, 2014.

  1. Fabkins

    Fabkins

    Joined:
    Jul 16, 2012
    Posts:
    7
    Whats a good way of making a GUI element either visible/invisble or active/inactive.

    Using active/inactive is a pain as you need to manage the object. Is there a way of turning the renderer off ?
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Simply disabling the UI (Image/ Text/ ...) Component stops the element from rendering.
     
  3. Fabkins

    Fabkins

    Joined:
    Jul 16, 2012
    Posts:
    7
    If you mean Active/Inactive is annoying as you need to manage the objects.

    I tried using "enabled" but it doesn't seem have a traditional renderer , so :

    gameObject.renderer.enabled = false;

    Doesn't work.
     
  4. Fabkins

    Fabkins

    Joined:
    Jul 16, 2012
    Posts:
    7
    Ok, worked out a way of doing it at least to the Canvas which might be good enough.

    gameObject..GetComponent(Canvas).enabled = false;
     
  5. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Right, that's because the rendering is done from the Component itself. For example, try:

    Code (csharp):
    1. yourObject.GetComponent<Button>().enabled = false;
    EDIT: Ah, beat me to it! And I see you're using JS. But yeah, that's the way to go then. =)
     
    Fabkins likes this.