Hi, I’m trying to come up with a script that will activate one of two cubes upon the player clicking. so at first there are no cubes visible, then you click and one (lilCube) becomes visible, then you click again and the second (bigCube) becomes visible. The code I have right activates both instantly, with only one click, even though I’ve tried adding a variable for how many times you’ve clicked. I’m not sure what would be an efficient way to check if the first cube is active yet, and if not, activate it, and then if it is, activate the second. Here is my code:
public GameObject lilCube;
public GameObject bigCube;
int clickTimes = 0;
void Start ()
{
lilCube.SetActive(false);
bigCube.SetActive (false);
}
void Update()
{
if (Input.GetButton ("Fire1") && lilCube.activeInHierarchy == false && clickTimes == 0)
{
lilCube.SetActive (true);
clickTimes = 1;
}
if (Input.GetButton ("Fire1") && lilCube.activeInHierarchy == true && clickTimes == 1)
{
bigCube.SetActive (true);
clickTimes = 2;
}
}
Also, if I get this working, what would be an efficient way to do it for 10 cubes or more without making a cube prefab? Prefabs won’t work for what I’m using this script for. Would I just have to keep doing more and more complicated if statements? there has to be a better way. I’m new to coding. sorry.