【问题标题】:Unity3D: adding Multi-Tap inputUnity3D:添加多点输入
【发布时间】:2015-09-03 07:47:18
【问题描述】:

如何在 Unity3D 游戏中添加多点点击(不是多点触控!)输入?我很难找到任何有用的信息。

到目前为止,我得到的是多点触控输入支持。这就是我正在使用的:

    private Vector2 _touchOrigin = -Vector2.one;

    public bool TouchEnded(int touchCount = 1)
    {
        if (Input.touchCount != touchCount) return false;
        Touch lastTouch = Input.GetTouch(touchCount - 1);
        if (lastTouch.phase == TouchPhase.Began)
        {
            _touchOrigin = lastTouch.position;
        }
        else if (lastTouch.phase == TouchPhase.Ended && _touchOrigin.x >= 0)
        {
            _touchOrigin.x = -1;
            return true;
        }
        return false;
    }

我想做的是编写一个类似的方法,但用于多次点击。 IE。用户必须同时点击多个手指(touchCount)多次(tapCount)。这将是方法签名:

    public bool TapEnded(int touchCount = 1, int tapCount = 2)
    {
    }

有人可以帮我解决这个要求吗?

【问题讨论】:

    标签: c# unity3d multi-touch


    【解决方案1】:

    您可以使用 Input.Touches 返回表示上一帧期间所有触摸状态的对象列表。参考链接http://docs.unity3d.com/ScriptReference/Input-touches.html

     void Update() {
        int fingerCount = 0;
        foreach (Touch touch in Input.touches) {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                fingerCount++;
    
        }
        if (fingerCount > 0)
            print("User has " + fingerCount + " finger(s) touching the screen");
    
    }
    

    【讨论】:

    • 但这只是关于触摸事件,而不是点击事件。我需要的是在特定矩形区域上双击或多击(可能使用 Touch.tapCount)。它也应该适用于 Android。
    猜你喜欢
    • 1970-01-01
    • 2019-08-05
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 2017-01-24
    相关资源
    最近更新 更多