button.OnClick listener triggers twice
Hello,
I have a play button in my scene which changes the current menu scene to the actual level scene.
I added the listener method in the form of a delegate:
playLevel.onClick.AddListener(delegate { LoadLevel();})
Most of the times it works perfectly fine, but sometimes when I click the button the game lags for a second and the button can be clicked again therefore opening the Level scene twice.
Does anyone have any idea on how to prevent this from happening? Thanks
Answer by MaxOR_PrimE · Oct 14, 2020 at 07:30 AM
you can just create a bool variable ... when you load the level set it to true. from there in your LoadLevel function load only if the bool variable is false
Your answer
Follow this Question
Related Questions
How to tell when a user is done interacting with UI.Slider? 0 Answers
Execution order of custom events 1 Answer
How to write and return a call for AddListener 1 Answer
Event NullReferenceException 1 Answer
Different approach to an upgrade system 4 Answers