Search Unity

Get UI Panel reference in Scripting (Where can I find the Panel-Class?)

Discussion in 'UGUI & TextMesh Pro' started by ClaasM, Oct 22, 2014.

  1. ClaasM

    ClaasM

    Joined:
    Oct 4, 2014
    Posts:
    26
    Hey,

    Im trying to get a Scripting reference to a UI Panel I use in my Scene to toggle its visibility in-code,
    but i cant figure out where to find the Panel class? It's not under UnityEngine.UI like other UI Elements and neither the scripting API nor the Manual or any Unity Tutorial could give me an answer.

    I hope somebody knows where to find the Panel.
    Regards,
    Claas M.
     
  2. Rodyfish

    Rodyfish

    Joined:
    Sep 4, 2014
    Posts:
    18
    There is no need to have a reference to a Panel, since the Panel itself does nothing. There are no special scripts or components to a Panel. Ill make a reference to a RectTransform instead.
     
    StickCannon and ClaasM like this.
  3. ClaasM

    ClaasM

    Joined:
    Oct 4, 2014
    Posts:
    26
    Worked, Thanks!
     
  4. GAMES89

    GAMES89

    Joined:
    May 29, 2018
    Posts:
    1
    I want to use the panel as a button to fly my object. How can I do it.
     
  5. nayefmhmd

    nayefmhmd

    Joined:
    Nov 9, 2019
    Posts:
    1
    Simply add a public filed in your script as GameObject , then drag and drop Panel Ui Object In public Field of your Script component.
     
    Jroel and pferreirafabricio like this.
  6. Mathius123

    Mathius123

    Joined:
    May 21, 2018
    Posts:
    14
    Another trick you can do is create an empty Monobehaviour class called something like "UIPanel.cs" with nothing in it except a blank declaration of the class itself, then attach that as a script component only to the Panels you are interested in getting references to. Then you can do a GetComponentsInChildren<UIPanel>() call (or whatever) and get all of them in one go. I use this trick for all sorts of game objects I want to grab that would otherwise be too much clutter in the inspector to manually assign, too many game objects returned (especially in the case of using a RectTransform in a UI to return Panels) or where Unity itself doesn't have a unique type for me to pull from.