如果玩家单击空白 space unity 2d 则播放
play if the player click in a blank space unity 2d
我正在为手机制作 2d 游戏并在 canvas 上创建了一个暂停按钮。问题是当我点击暂停按钮时,播放器会射击。我希望有一种方法可以在触摸 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();
}
}
我正在为手机制作 2d 游戏并在 canvas 上创建了一个暂停按钮。问题是当我点击暂停按钮时,播放器会射击。我希望有一种方法可以在触摸 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();
}
}