【问题标题】:play if the player click in a blank space unity 2d如果玩家在空白处单击统一 2d,则播放
【发布时间】:2021-01-16 01:14:00
【问题描述】:

我正在为移动设备制作 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();
            }
        }

【问题讨论】:

    标签: c# unity3d 2d


    【解决方案1】:

    检查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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多