Hello all,
I have been doing some UI research for my game and found many useful things, but I’m stumped with this problem. First, I found a great way to make buttons that are just textures from here:
And I am combining that with GUI.toggle documentation found here:
Now, what I want to do is to toggle multiple button “states” so to speak. Let’s say I have buttons A, B and C. Pressing A or B will turn on a “state”, lets call them SpeedOn and StrengthOn. These states correspond to different textures which, if they are on, should apply the appropriate texture to button C when it is clicked. Hence, if i click on SpeedOn button (button A), then click on button C, the “SpeedOn” texture will appear on button C. Instead, if I have clicked on the “StrengthOn” button (button B), the texture associated with StrengthOn should appear on button C.
There are more than 2 different states so it won’t be a simple matter like toggling a button on or off. There are at least 4 right now, but the rest are omitted for simplicity.
I hope I have explained that clearly enough. I have made some changes due to feedback and suggestions. But I am still unsure of what to put in button C’s if statement. Here is the code I have so far:
These turn on the states (buttons A and B):
if (GUI.Button(new Rect(5, 20, 52, 52), spd))
{
speedon = true;
}
if (GUI.Button(new Rect(5, 72, 52, 52), str))
{
strengthon = true;
}
This is the code for when you click button C. Before receiving a state, it is simply an empty button:
CheckChosen();
if (GUI.Button(new Rect(203, 79, 20, 20), " "))
{
//What should go in here?
}
Finally, this function checks which state is on, so it can choose the appropriate texture to put on button C:
void CheckChosen()
{
if (speedon)
texturetoapply = spd;
if (strengthon)
texturetoapply = str;
if (viton)
texturetoapply = vit;
}