我正在制作一款2d手机游戏,并在画布上创建了一个暂停按钮。问题在于,当我点击暂停按钮时,玩家会射击。我希望当触摸在UI的一个元素上时,有一种方法可以阻止镜头。有什么简单的方法吗?
这是我用来检测点击的代码:
if(Input.touchCount > 0)
{
touch_ = Input.GetTouch(0);
if(touch_.phase == TouchPhase.Began)
{
touching = true;
touch_began_fun();
}
if(tocando)
{
toching_fun();
}
if(touch_.phase == TouchPhase.Ended)
{
touching = false;
touch_ended_fun();
}
}
检查EventSystem当前选择的游戏对象是否为空。如果它不是空的,触摸是在一个UI元素。
if(Input.touchCount > 0)
{
touch_ = Input.GetTouch(0);
if(touch_.phase == TouchPhase.Began && EventSystem.current.currentSelectedGameObject == null)
{
touching = true;
touch_began_fun();
}
if(tocando)
{
toching_fun();
}
if(touch_.phase == TouchPhase.Ended)
{
touching = false;
touch_ended_fun();
}
}