- Home /
How to set toggle values???
Friends, how to set toggles values if I have 4 toggles in 1 toggle group? and then how to get the values which checked if i have 4 toggle groups? because i wanna calculate the values which checked. please help me :(
Answer by Larry-Dietz · Dec 25, 2017 at 12:38 AM
To determine or set a toggle's check, just check/set the IsOn boolean variable on the toggle.
So, just check each toggle and do your calculation based on which ones have an IsOn property set to true.
Hope this helps, -Larry
can you give me an example script please? I'm still newbie for this. thank you :)
Here is a quick example to check 3 toggles, and write to the console which ones are checked.
Toggle toggle1;
Toggle toggle2;
Toggle toggle3;
void WhatToggleIsOn() {
if (toggle1.IsOn)
Debug.Log("Toggle1 is checked");
if (toggle2.IsOn)
Debug.Log("Toggle2 is checked");
if (toggle3.IsOn)
Debug.Log("Toggle3 is checked");
}
Here is another example to set the checkmark...
Toggle toggle1;
Toggle toggle2;
Toggle toggle3;
void SetToggles () {
toggle1.IsOn=true;
toggle2.IsOn=false;
toggle3.IsOn=true;
}
This will set toggles 1 and 3 to checked, and toggle2 to unchecked.
Hope this helps, -Larry
thanks, friend. but i wanna set toggle value as integer. is it possible?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Toggle ON/OFF MaterialChange 0 Answers
Distribute terrain in zones 3 Answers
Illustrating Sorting Process of Balls In Unity Using Sorting Algorithms 0 Answers
how to use custom word as KeywordRecognizer in Unity 0 Answers