-3

I'm trying to code adversaries to move between two points and destroy the player if touched.

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

}

No overload for method 'Distance' takes 1 arguments."

How to fix it?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Captain Cat
  • 21
  • 1
  • 3
  • 1
    What part of error message is confusing to you? It is very hard to provide *useful* help without that information. – Alexei Levenkov Apr 06 '16 at 17:04
  • In current state of the question it does not look like any different from thousands of similar once that could be found by searching for error message - (i.e. http://stackoverflow.com/questions/19517794/how-to-fix-no-overload-for-method-takes-0-arguments I used as duplicate). If that does not provide enough explanation - make sure to edit your question to clarify what you don't understand (may need to ask new, more specific question for that). – Alexei Levenkov Apr 06 '16 at 17:10

1 Answers1

0

The Distance call returns the distance between two points but the code you wrote only gives one point. I think you have a "-" where you wanted a",".
Try this:

if (Vector3.Distance(transform.position, keyPoints[currentKeyPoint].position) <= min_Distance) 
Brian from state farm
  • 2,825
  • 12
  • 17