I want to activate and deactivate a child of a gameobject by clicking on this gameobject with the mouse. When I start in game mode the child is not activated and when I click for the first time on the gameobject it is activated. Until now it’s good, the problem comes next when I click again in the same gameobject and nothing happens. I was expecting the child to disappear but it continues there.
I’ll put the code here so you can see. Maybe it’s the functions of activeself that aren’t working but this makes sense to me.
using UnityEngine;
using System.Collections;
public class ActivateGizmo : MonoBehaviour {
private GameObject child;
void Start()
{
child = gameObject.transform.GetChild (0).gameObject;
}
void OnMouseDown()
{
if (child.activeSelf == false)
{
child.SetActive (true);
} else if (child.activeSelf == true)
{
child.SetActive(false);
}
}
}