Hi,
I’m unfamiliar with Unity, and so I was hoping that I could get some help in making this work.
Basically,
A toggle with three levels.
Upon clicking the toggle it raises up one level, drawing a GUItexture (a little circle or square) in the process.
if(GUI.Button(new Rect(10,370,100,20),"Defense","toggle"))
{
Debug.Log("Defense level toggled");
//In here, I'd have something that would draw a texture to represent the texture
//something like initialize an array of three 2dtextures
//and then I'd combine the array and the toggles to make it draw the textures.
//I have no idea of how to do this.
defense++;
}
I don’t know where to go from there. Can someone help me out, please?
I’d greatly appreciate it.
public int selected = 0;
public GUIContent[] contents;
void OnGUI()
{
selected = TierToggle(new Rect(10, 370, 100, 20), selected, contents);
// Do things here.
}
int TierToggle(Rect position, int selected, GUIContent[] contents)
{
if (selected < 0)
selected = 0;
if (selected >= contents.Length)
selected = contents.Length - 1;
if (GUI.Button(position, contents[selected]))
{
selected++;
if (selected >= contents.Length)
selected = 0;
}
return selected;
}
As you can see, it is not terribly hard. Use a GUIContent Array to define the textures you want to use. The TierToggle control defined here just uses a button that increases the value of selected until it is too high, then starts it over at the minimum level, and returns it so you can use that information to access a value in an array.
EDIT: Fixed a mistake and altered the arguments of TierToggle to make more sense. (It was silly to give it one content and the bottom/top bounds of selected when providing the content array could be used to solve all three problems automatically.)
Thanks! This code returns an error stating that not all codepaths return, from the function, TierToggle. How do I fix this error? I don’t see what I would do to make it return.