The question is answered, right answer was accepted
Button method before the next Update frame
Hello I have an Update method in my playerController Script:
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began && pauseActive == false)
{
StartCoroutine(JumpUpDown(jumpDir));
jumpDir *= -1;
}
}
}
So when I press the button on the screen, this method is called inside my UI class:
public void Pause()
{
playerController.pauseActive = true;
}
however, Update is called first, so my coroutine starts. How do I call Pause() first, before the Update() method, when I press the button? *Mobile
Answer by Cuttlas-U · Feb 09 at 12:18 PM
hey , just use the same condition in update so it has also to wait a frame
void Update()
{
if (Input.touchCount > 0 && playerController.pauseActive == true)
Answer by Deksover · Feb 09 at 12:26 PM
This worked
if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
}
Follow this Question
Related Questions
the player input is jittery seems like glitching 0 Answers
How to receive input on specific objects -Android 0 Answers
Get the distance of a touch while touch phase is moved 2 Answers
Move two players in the same Screen (Input.TouchCount) 1 Answer
How do I adjust code so gyro translates player to center position when device is being held in hands 1 Answer