【问题标题】:No overload for method 'Distance' takes 1 arguments [duplicate]方法'Distance'没有重载需要1个参数[重复]
【发布时间】:2016-04-06 16:59:25
【问题描述】:

我正在尝试对对手进行编码,使其在两点之间移动并在触碰玩家时摧毁玩家。

public class MovementBetweenPoints : MonoBehaviour {
    public Transform[] keyPoints;
    public float speed;
    private int currentKeyPoint;
    public float min_Distance;
    public float Distance;

    // Use this for initialization
    void Start () 
    {
        transform.position = keyPoints[0].position;
        currentKeyPoint = 1;
    }

    // Update is called once per frame
    void Update () 
    { 
        // ----------- Error happens on next line
        if (Vector3.Distance(transform.position - keyPoints[currentKeyPoint].position) <= min_Distance)   
        {
            currentKeyPoint++;
        }

        if (currentKeyPoint >= keyPoints.Length)
        {
            currentKeyPoint = 0;
        }

        transform.position = Vector3.MoveTowards(transform.position, keyPoints[currentKeyPoint].position, speed * Time.deltaTime);
    }

    void OnTriggerEnter(Collider Player)
    {
        Destroy(Player.gameObject);
    }

}

方法 'Distance' 没有重载需要 1 个参数。"

如何解决?

【问题讨论】:

  • 错误信息的哪一部分让您感到困惑?没有这些信息,很难提供有用的帮助。
  • 在问题的当前状态下,它看起来与通过搜索错误消息可以找到的数千个类似情况没有任何不同 - (即stackoverflow.com/questions/19517794/…我用作重复项)。如果这不能提供足够的解释 - 请务必编辑您的问题以澄清您不理解的内容(可能需要为此提出新的、更具体的问题)。

标签: c# unity3d unityscript


【解决方案1】:

Distance 调用返回两点之间的距离,但您编写的代码只给出了一个点。我认为你有一个“-”,你想要一个“,”。
试试这个:

if (Vector3.Distance(transform.position, keyPoints[currentKeyPoint].position) <= min_Distance) 

【讨论】:

  • 就是这样!非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2012-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多