2016-04-06 77 views
-3

我想編碼對手在兩點之間移動並摧毀玩家,如果觸摸。沒有超載的方法'距離'需要1個參數

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

在問題的當前狀態中,它看起來沒有任何與成千上萬的類似的任何不同,可以通過搜索錯誤消息來找到 - (例如http://stackoverflow.com/questions/19517794/how-to-fix-no -overload-for-method-takes-0-arguments我用作重複)。如果這不能提供足夠的解釋 - 確保編輯你的問題,以澄清你不明白的東西(可能需要爲此提出新的更具體的問題)。 –

回答

0

Distance調用返回兩個點,但你寫的代碼之間的距離只有一點,我認爲你有一個「 - 」,你想要一個「,」
試試這個:

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

就是這樣!非常感謝你的幫助! –

相關問題