简体   繁体   中英

Is there a way to find if last pressed item was a UI element after touch has ended in Unity

I'm making a 2D infinite run platform game in which the player jumps after the Touch input ends. My game has some UI button elements in it too. But my character is jumping when i'm returning from main paused screen to game screen. Here is the code i tried.There is some issue with touch.phase==touchphase.end and not working together.but for some reason JumpAndResetPower() gets executed even though i clicked on resume button on UI.

if(Input.touchCount>0)
    {

        Touch touch = Input.GetTouch(0);

        if(touch.phase==TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
        {
            accumilateJumpPower();
        }
        else if(touch.phase==TouchPhase.Ended && !EventSystem.current.IsPointerOverGameObject(touch.fingerId))
        {
            JumpAndResetPower();
        }
    }

The way I got around it is by using aa variable that's set every time I press the pause button. And later when I press the play button, the jumping code will only get executed if variable is not set. Else if variable is set it will unset the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM