Hello Guys, I’ve been working on a script for 2 days but I coudn’t handle. so my script is this;
#pragma strict
//List of ducks
static var duckList : GameObject[];
//Speed of Crocodile
var speedCroco : float;
function Start () {
}
function Update () {
//Move to one of the ducks selected from Array
transform.position = Vector3.MoveTowards (transform.position, duckList[Random.Range(0, duckList.Length)], speedCroco * Time.deltaTime);
}
So Debug Log gaves me this error. “The best overload for the method ‘UnityEngine.Vector3.MoveTowards(UnityEngine.Vector3, UnityEngine.Vector3, float)’ is not compatible with the argument list ‘(UnityEngine.Vector3, UnityEngine.GameObject, float)’.” I didn’t understand what is it meaning ? So Please Help !
Which means, MoveForwards takes in a Vector3, a Vector3 and a float, but you are passing in a Vector3, a GameObject and float.
Your DuckList is an array of GameObjects, so when you get a random gameobject from the array, you can’t just pass that gameObject to MoveForwards. Instead you probably want it’s position which you access by .transform.position like this:
Now, with that said, you might still get an error with the code you’ve provided since you don’t ever assign anything to that array, but I’m hoping that the code you posted was just for the sake of demonstration.