- Home /
Make panel inactive on second click
I have this code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class InfoScript : MonoBehaviour {
public GameObject aboutDialog;
void Start() {
if (aboutDialog != null)
{
aboutDialog.SetActive (false);
}
else
{
Debug.LogError ("Missing the aboutDialog on the UIManager00");
}
}
public void OnMouseUpAsButton()
{
{
if (aboutDialog != null) {
aboutDialog.SetActive (true);
} else {
Debug.LogError ("Missing the aboutDialog on the UIManager00");
}
}
}
}
which is attached to a cube. When I start the scene, the cube in in the scene but the panel is inactive. When I click the cube, the panel becomes active and show some text info about the cube. How can I make it so that when I click the cube for a second time, the panel becomes inactive again? Have spent hours googling and trawling the literature and there seems to be no simple way to do this?? Sorry if stupid question but I am new and dumb and Unity is hard
Change line 21 to
aboutDialog.SetActive (!aboutDialog.activeInHierarchy);
This will change the state of the GAmeObject (Active/Inactive) regarding its current state. Cheers.
Answer by Hellium · Dec 04, 2017 at 03:56 PM
You may be looking for activeSelf
if (aboutDialog != null) {
aboutDialog.SetActive (!aboutDialog.activeSelf);
} else {
Debug.LogError ("Missing the aboutDialog on the UIManager00");
}