How can I make a UI button's action happen before `Input.GetMouseButtonDown` action in another script?
Hello!
When I click my pause button I call this function
public void PauseGame()
{
fcs.enabled = false;
Time.timeScale = 0;
pcs.ActivateCanvas();
pauseButton.SetActive(false);
}
fcs is another script and that script uses
void Update()
{
if (Input.GetMouseButtonDown(0))
{
spawnPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//And a bunch of code in here that I don't think matters to spawn a gameobject
}
}
When I pause the game I want to deactivate the fcs script, which it does, but in some cases the button is positioned at a possible spawn point for the gameobject in Update which makes it first spawn that object and then pause the game and deactivate the script.
.
I assume this is because the button triggers on ButtonUp but the spawning of gameobjects triggers on ButtonDown but I can't really figure out how to solve this.
.
Does anyone know of a solution to make the button trigger instantly and in that way trigger fcs.enabled = false;
before it can spawn a new gameobject (or any other way to solve this)? I've tried adding them to the script execution order list but that did not help.
Appreciate any help, thank you!
can you test using LateUpdate rather than Update? it is the same as updat ebut excuted last.
I tried it, but unfortunately it did not help. Thx though!
and maybe the On Gui? cant you use a raycast for making sure when you get the mouseposition isnt over an ui element? or using the pointer event
Your answer
Follow this Question
Related Questions
Problems with UI buttons and Cursor position (or) UI buttons and instantiated canvas. 1 Answer
Script attached on prefab; cannot attach "text" component 1 Answer
hey im trying to make a pause menu, it keeps poping up at the start and i have no idea how to fix. 1 Answer
Problem with scrolling list of buttons in UI 0 Answers
Tap battle system help! 0 Answers