Hi All,
Need help with my script on StartCoroutine.
I have this error message in my Console in Unity 5.5
Assets/Scripts/EvasiveMovement.cs(23,3): error CS1502: The best overloaded method match for `UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)’ has some invalid arguments
and the below is the script on my EvasiveManeuver.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EvasiveMovement : MonoBehaviour
{
public Vector2 startWait;
public float dodge;
public float tilt;
public Vector2 movementTime;
public Vector2 movementWait;
public float smoothing;
public Boundary boundary;
private float currentSpeed;
private float targetMovement;
private Rigidbody rb;
void Start ()
{
rb = GetComponent ();
currentSpeed = rb.velocity.z;
StartCoroutine (Evade ());
}
IEnumerable Evade ()
{
yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y));
while (true)
{
targetMovement = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
yield return new WaitForSeconds (Random.Range (movementTime.x, movementWait.y));
targetMovement = 0;
yield return new WaitForSeconds (Random.Range (movementWait.x, movementWait.y));
}
}
void FixedUpdate ()
{
float newMovement = Mathf.MoveTowards (rb.velocity.x, targetMovement, Time.deltaTime * smoothing);
rb.velocity = new Vector3 (newMovement, 0.0f, currentSpeed);
rb.position = new Vector3
(
Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
);
rb.rotation = Quaternion.Euler (0, 0, rb.velocity.x * -tilt);
}
}
I have another StartCoroutine in the Game Controller for spawnWaves and it works fine. but for this one, it doesn’t work.
Please help.
Thanks alot,
Your Newbie friend.