- Home /
EventSystems with pause button
So everyone has been awesome helping me with eventsystems so that clicking on a UI Button does not pass through and call the Player movement.
Here's what's working. When the game is paused if i touch anything in the pause menu the game will continue and will not register the mouse click for movement but only for "resume" or whatever else i decide to interact with in the pause menu.
Here's what's not working. My Pause button itself that pauses the game and calls up the pause menu is calling the movement method at the same time i press pause. So while all activity stops, when i click resume the player will finish their movement path towards the pause button.
The good is that the player finishes it's path that was called when pushing the resume button. the bad is that that path will always be towards the pause button.
How do i get pressing the pause button to not call the movement method.
Here's the script.
public class Player : MonoBehaviour {
private void Movement()
{
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
else
{
if (Input.GetMouseButtonDown(0))
{
_myPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
_myPosition.z = transform.position.z;
_animator.SetTrigger("Player_Run");
}
transform.position = Vector3.MoveTowards(transform.position, _myPosition, _speed * Time.deltaTime);
}
}
}