- Home /
How do i detect if toggle has been unchecked
If my toggle has been unchecked I need a Int to be decremented, I hope someone can help.
public void PistolToggle()
{
if (UseButtons.PistolPurchased == true)
{
if (ItemsSelected < 2)
{
//Select this item for use Incrementing ItemSelect to so that they cannot use more than 2 Items.
PistolSelected = true;
ItemsSelected += 1;
// If the Index is already used Check if Index2 is being used and put it in an empty one.
if (Index1Used == false)
{
ItemIndex1 = 1;
Index1Used = true;
}
else
{
if (Index2Used == false)
{
ItemIndex2 = 1;
Index2Used = true;
}
}
}
else
{
// If there is More than 2 items show an alert notifying the user that they cannot select more than 2 items.
StartCoroutine(HideAlert());
}
}
else
{
//If the item is not purchased notify the user that They do not own the item.
StartCoroutine(Alert2());
}
}
Sorry this is a huge mess, though as you can see I am using a ItemsSelected int which if its <2 it lets me follow through with script, Though if the user chooses to unselect an item because they changed their mind I need it to remove 1 from ItemsSelected so they can then choose another item.
That's really helpful, Thanks!. Though, How do i go around using this, Is there a way I can use it in the same script.
Yes, you can use it on the same script. It's pretty much a copy-paste from the sample code with an extra if-statement in the callback function to check if the toggle just switched off.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Toggles/Toggle Groups Question 0 Answers
Do Something ONLY when all Toggles are On or Off 4 Answers
Scripting button functionality inside class with created object's method 1 Answer