Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question I don't know why is it not working?

Discussion in 'Scripting' started by unity_TR7C4xry9zxIAw, Dec 16, 2020.

  1. unity_TR7C4xry9zxIAw

    unity_TR7C4xry9zxIAw

    Joined:
    Jul 8, 2020
    Posts:
    26
    Hello,

    I have seven objects and buttons. I want to make sure that when I press the button, I see the object and if the button is not pressed, I don't want to see the object. So, I set up the OnClick() event : Gameobject.SetActive. When i press play mode and button, object is not showing.

    How to solve this problem?
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    In the OnClick event, after choosing the SetActive function, did you click the checkbox that appeared? SetActive takes a bool argument--that is, you can say SetActive(true) to enable an object or SetActive(false) to disable it--so if the check box is NOT checked, you are turning it off rather than turning it on.
     
  3. unity_TR7C4xry9zxIAw

    unity_TR7C4xry9zxIAw

    Joined:
    Jul 8, 2020
    Posts:
    26
    Yeah, I already checked.
    When button 1 of the 7 buttons is pressed, object A is visible (button 1 is set to show only object A, the rest is not checked). Button 2 was set to show only object B, and previous object A and the rest were set to be invisible. Then when button 2 is pressed, nothing is visible(Object A is also invisible and object B is invisible).
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    If it worked for button 1 showing object A, but not for button 2 showing object B, then something is different between the two. Possibly an error in your button configuration, possibly a different in your object hierarchy, possibly a difference in the way the object draws itself.