what replaces Toggle Using Button Style in New GUI?
I would like to create toggles that look like regular buttons, or would like regular buttons to act as Toggles using the new Unity3D GUI (post 4.6) I'm on version 5.1.3. I've been searching and cannot find any documentation or tutorials that show how to do this in the new GUI. All Unity3D documentation I've found only shows how to do this in the legacy UI. I've already gone through this as well, in hopes of finding the answer: http://www.raywenderlich.com/114828/introduction-unity-ui-part-1 and the 2nd and 3rd part as well, but it doesn't show what replaces the toggle Using button style...
Hopefully a simple solution. Thanks in advance!
I've figured out how to make a Button act like a Toggle with the below code in my UI$$anonymous$$anager C# Script, and assigning (in the INSPECTOR) the GameObject "Pressed" to the UI$$anonymous$$anager script. HOWEVER: The button still appears like a button. When I press it, it momentarily changes color, but does not stay the same color. I am thinking I need to fetch a different image from within the script? public class TabletUI : $$anonymous$$onoBehaviour { public GameObject Pressed;
private bool toggle = false;
public void PB_1()
{
if (!toggle)
{
Pressed.SetActive(true);
toggle = true;
Debug.Log("Sirens ON");
}
else
{
Pressed.SetActive(false);
toggle = false;
Debug.Log("Sirens OFF");
}
}
}
Answer by AnnaB417 · Mar 16, 2016 at 09:52 PM
Ultimately, the TOGGLE UI element seems to replace the Toggle usingButton function. I've now got my project set up and working as intended by using 2D sprites and "sprite swap" in the Toggle transitions. So I've got one set of images to look like buttons off (not lit up) and another set of images that look like buttons turned on (indicator lights on). The Unity GUI interface sets up the Toggle as a Bool, so when clicked it returns "is on" for true, and unclicked for false. No addition scripting needed!