【问题标题】:no overload for method get touch takes 0 arguments [closed]方法 get touch 没有重载需要 0 个参数 [关闭]
【发布时间】:2019-12-20 11:51:12
【问题描述】:

代码:

void Update(){
    if (Application.platform == RuntimePlatform.Android) {
        foreach (Touch touch in Input.GetTouch()) {
            if (touch.fingerId == 0) {
                if (!GameManager.instance.isPlaying) {
                    GameUIManager.instance.showStartGameCanvas (false);
                    GameManager.instance.isPlaying = true;

                    myRiggidBody.constraints = RigidbodyConstraints2D.FreezePositionX;
                }
                isJump = true;
            }
        }
    }

现在出现错误“get touch 方法没有重载需要 0 个参数”

需要帮助;)

【问题讨论】:

  • 阅读Input.GetTouch() 描述。它需要一些参数。
  • public static Touch GetTouch(int index)
  • 您可能更想遍历包含所有触摸信息的Input.touches

标签: c# unity3d


【解决方案1】:

之所以如此,是因为Input.GetTouch(...) 方法需要一个参数(int index)。检查documentation

【讨论】:

    【解决方案2】:

    查看https://docs.unity3d.com/ScriptReference/Input.GetTouch.html

    public static Touch GetTouch(int index);

    索引:设备屏幕上的触摸输入。

    Input.GetTouch 为选定的屏幕触摸(例如,从手指或触控笔)返回 Touch。触摸描述屏幕触摸。 index 参数选择屏幕触摸。

    获取有关触摸计数的信息

    Input.touchCount 提供当前的屏幕触摸次数。如果 Input.touchCount 大于零,则 GetTouch 索引设置要检查的屏幕触摸。 Touch 返回一个带有屏幕触摸细节的结构。每次额外的屏幕触摸都会使用一个递增的 Input.touchCount。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      相关资源
      最近更新 更多