Search Unity

Question UI Reappear.

Discussion in 'Scripting' started by Corrothon, Apr 22, 2021.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Hello, I'm trying to have this UI Reappear.
    When you load in to the game it appears and when you click on it, it disappears but if the player want to open it again they can press on a trigger button.
    Now the thing is, the trigger button won't work!
    Here's the open and close script:
    Code (CSharp):
    1. // Start is called before the first frame update
    2.     void Start()
    3.     {
    4.         UiObject.SetActive(true);
    5.  
    6.     }
    7.     // Update is called once per frame
    8.     void Update()
    9.     {
    10.         if(Input.GetMouseButtonDown(0))
    11.         {
    12.             UiObject.SetActive(false);
    13.         }
    and here is the trigger button script:
    Code (CSharp):
    1.     // Start is called before the first frame update
    2.     void Start()
    3.     {
    4.  
    5.     }
    6.     // Update is called once per frame
    7.     void Update()
    8.     {
    9.        if(Input.GetMouseButtonDown(0))
    10.         {
    11.             UiObject.SetActive(true);
    12.         }
    13.     }
    14.    
    edit: (they are different scripts)
     
  2. - delete the second script unless you really need that for something else
    - make a function in the first script for example ToggleUIObject (I advise you to name it something more concrete, both the UIObject and the function name with it).
    - in that function toggle the UI like
    UiObject.setActive(!UiObject.activeSelf);

    - then you can add this game object / function to the button's OnClick event in the inspector
     
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    The other button is to bring up the menu again and that's what I'm trying to do. this didn't work but thanks for at least responding, I'm just going to scrap this from the game
     
  4. Well... okay then...
     
    Joe-Censored likes this.