[英]Instantiated class with “new” keyword is null after Start method has ended and button is pressed. Unity3d
[英]Is there a way to find if last pressed item was a UI element after touch has ended in Unity
我正在制作一个 2D 无限运行平台游戏,其中玩家在触摸输入结束后跳跃。 我的游戏中也有一些 UI 按钮元素。 但是当我从暂停的主屏幕返回到游戏屏幕时,我的角色正在跳跃。 这是我试过的代码。 touch.phase==touchphase.end 存在一些问题并且不能一起工作。但是由于某种原因,即使我点击了 UI 上的恢复按钮, JumpAndResetPower() 也会被执行。
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();
}
}
我绕过它的方法是使用每次按下暂停按钮时设置的 aa 变量。 稍后当我按下播放按钮时,只有在未设置变量的情况下才会执行跳转代码。 否则,如果设置了变量,它将取消设置变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.