Home > Software engineering >  Unity script is running on any button click
Unity script is running on any button click

Time:06-07

I have a button called ShareButton in the below screenshot that is linked to a script and it works fine but the same action of the script is executed every time I click on any other button. The other buttons are not linked to the script but it keeps executing it while doing the right action of the button.

enter image description here

EDIT :

This is the other button that is just supposed to close the modal but is also running the script that has nothing to do with it. enter image description here

And this is the script of the 'ShareButton' : enter image description here

Anyone knows why ? Thanks

CodePudding user response:

well, you do your thing on Input.GetMouseButtonDown, completely regardless where on the screen this click happens!

Update is called by Unity automatically every frame, not only by your button click.

Instead of calling Update on button click you rather want to have e.g. a

public void TakeScreenShot()
{
    StartCoroutine(TakeScreenshotAndShare());
}

and call this in your button.

CodePudding user response:

may be you are calling that method inside script in another method. i can't help you unless you show your code.

  • Related