- Home /
Toggling a game objects active state
When working on a main menu i encountered this problem. i want a gameobject to be set to active when toggled when clicked toggle stays ticked and doesnt set the wind gameobject as not active
public Toggle wind;
GameObject windzone;
public void OnToggle ()
{
if(wind == true)
{
wind.isOn = true;
windzone.SetActive(true);
}
else
{
wind.isOn = false;
windzone.SetActive(false);
}
}
please format your code so that it's more readable.
you don't state anything about errors or what the code actually does/doesn't do. that's not a question which can be answered...
the code that you posted looks like it should toggle isOn
and the state of windzone
when called. what does it do? where is it being called from?
There isn't an OnToggle event for Toggle component.
You should use the OnValueChanged event that is on the bottom of the component.
Answer by PabloUnityArgentina · Dec 27, 2015 at 12:59 AM
I think there is not OnToggle event for Toggle component.
There is an event called OnValueChanged for Toggle component, on bottom of it.
So, your script should look something like this:
void HandleOnValueChanged()
{
// Do Whatever you want
}
Your answer
Follow this Question
Related Questions
[4.6] Toggle/Checkbox On/Off 1 Answer
Toggle Event passing bool [4.6+] 2 Answers
How can I reference a Toggle? 3 Answers
How to have a callback when a toggle is clicked in a toggle group? 3 Answers
UI toggle.onValueChanged assigning method via script 1 Answer