- Home /
How to initialize UI element without event
In my UI I have a method initializing a menu, also initializing a Toggle.
public void displayPlayer(Player player) {
// ...
isactiveToggle.isOn = player.isActive();
}
This leads to the Change Event is getting triggered and so methods are called, that should not be called just because the Menu was initialized.
public void makePlayerCurrentPlayer(Toggle toggle) {
// Stuff that should only happen, when the user activliy triggers the toggle
}
How can I prevent the callback method being triggered when changing the state of my Toggle from script?
EDIT:
Best I have so far:
private bool isInitializing = false;
public void displayPlayer(Player player) {
isInitializing = true;
// ...
isactiveToggle.isOn = player.isActive();
isInitializing = false;
}
public void makePlayerCurrentPlayer(Toggle toggle) {
if (!isInitializing) {
// Stuff that should only happen, when the user activliy triggers the toggle
}
}
Hope there exists something better.
Comment
Your answer
