- Home /
My function is called twice on single click
I am calling a method through the UI button , it is calling two times unexpectedly,
public void SkipBtnClick() { Debug.Log("skip pressed"); StartCoroutine("HealthSurveyRequest"); }
i also tried event trigger's pointer down to call this method but again its called two time. I have checked there is nothing behind the this button and there is only one place where mouse 0 is used as an alternative positive button i.e. Fire1. I also reduced sensitivity from 1000 to 1 in input settings.
Please post the full body of your code and a screen shot of the UI object and all of it's components in the hierarchy so everyone can help better. I'll try to assume what it could be though.
Are you using the UI built in OnClick event in the inspector or are you using the On$$anonymous$$ouseDown() event in your code? If it's doing it exactly twice, are you trying to do both? Don't do both. If that's not it I'll need to see all of the code and the components of the button.
Answer by xAdamQ · May 11, 2018 at 08:59 PM
You may have added the function to button's OnClick twice.
No,I have checked multiple times but i found it is called by once only. What i observed is that i am using startcoroutine() to wait for getting the URL through the www and due to this reason it is calling twice .
Answer by krispastas · Apr 13, 2020 at 02:33 PM
Hey, I now that I'm really late but this might help you https://forum.unity.com/threads/button-onclick-event-is-firing-twice.359933/