Hi, I have layers of blocks which when receiving a button press another layer of blocks is added.
here is my code:
var layer1: GameObject;
var layer2: GameObject;
var layer3: GameObject;
var layer4: GameObject;
var layer5: GameObject;
var btnUpTexture : Texture;
var btnDownTexture : Texture;
public var i : int = 1;
function Start()
{
layer1.SetActive(true);
layer2.SetActive(false);
layer3.SetActive(false);
layer4.SetActive(false);
layer5.SetActive(false);
}
function Update()
{
if(i == 1)
{
layer1.SetActive(true);
Debug.Log("Layer 1 Active");
}
if(i == 2)
{
layer2.SetActive(true);
Debug.Log("Layer 2 Active");
}
if (i == 3)
{
layer3.SetActive(true);
Debug.Log("Layer 3 Active");
}
if (i == 4)
{
layer4.SetActive(true);
Debug.Log("Layer 4 Active");
}
if (i == 5)
{
layer5.SetActive(true);
Debug.Log("Layer 5 Active");
}
}
function OnGUI() {
if (GUI.Button(Rect(10,10,50,50),btnUpTexture))
{
i++;
}
Debug.Log("Clicked Up" + i);
if (GUI.Button(Rect(10,70,50,30),btnDownTexture))
{
i--;
}
Debug.Log("Clicked Down" + i);
}
This works, but if I want go down a level SetActive(false) there will be a conflict as I cant have I == 5 SetActive(false) as the moment I show the layer it will remove the layer.
Should I set the value of the down button to a different value and have a if or statement? What is the best way of doing this?
Also I am aware I could probably simplify this quite abit, any ideas?