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

时间:2016-04-06 16:59:25

标签: c# unity3d unityscript

我正在尝试编写对手以在两点之间移动并在触及时摧毁玩家。

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);
    }

}
  

方法'距离'没有重载需要1个参数。“

如何解决?

1 个答案:

答案 0 :(得分:0)

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

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