I wanted to create a script, that moves an object in one direction and changes the direction of the movement every three seconds. But it returns error. Could you please see what is wrong here?
var speed = Vector3 (0, 0, 0);
function Start()
{
var randomDirection : Vector3 = new Vector3(Random.Range(-359, 359),0,Random.Range(-359, 359));
StartCoroutine(ChangeDirection(3.0));
}
function Update()
{
rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);
}
function ChangeDirection (waitTime : float)
{
yield WaitForSeconds (waitTime);
var randomDirection : Vector3 = new Vector3(Random.Range(-359, 359),0,Random.Range(-359, 359));
StartCoroutine(WaitAndStart(1.0));
}
function WaitAndStart (waitTime : float)
{
yield WaitForSeconds (waitTime);
var randomDirection : Vector3 = new Vector3(Random.Range(-359, 359),0,Random.Range(-359, 359));
StartCoroutine(ChangeDirection(3.0));
}
Error is:
1)Assets/Blind_Scripts/Random_2D_Movement.js(35,16): BCE0070: Definition of ‘Random_2D_Movement.WaitAndStart’ depends on ‘Random_2D_Movement.ChangeDirection’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.
2)Assets/Blind_Scripts/Random_2D_Movement.js(35,15): BCE0023: No appropriate version of ‘UnityEngine.MonoBehaviour.StartCoroutine’ for the argument list ‘(unknown)’ was found.