C# 如果玩家在空白处单击,则播放
我正在为手机制作一个2d游戏,并在画布上创建了一个暂停按钮。问题是,当我点击暂停按钮时,玩家会开枪。我希望当触摸在UI的某个元素上时,有一种方法可以阻止拍摄。 有什么简单的方法可以做到这一点吗 这是我为检测点击而编写的代码:C# 如果玩家在空白处单击,则播放,c#,unity3d,2d,C#,Unity3d,2d,我正在为手机制作一个2d游戏,并在画布上创建了一个暂停按钮。问题是,当我点击暂停按钮时,玩家会开枪。我希望当触摸在UI的某个元素上时,有一种方法可以阻止拍摄。 有什么简单的方法可以做到这一点吗 这是我为检测点击而编写的代码: if(Input.touchCount > 0) { touch_ = Input.GetTouch(0); if(touch_.phase == TouchPhase.Bega
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当前选定的游戏对象是否为空。如果不为null,则触摸在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();
}
}
检查EventSystem当前选定的游戏对象是否为空。如果不为null,则触摸在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();
}
}