StartCoroutine error message in C#
I was doing the Space Shooter Tutorial and everything was going fine when I got an error message when I was working on the wave spawning code. It appeared on the line of my StartCoroutine code. Also, I am very new to Unity.
Error: Error CS1502: The best overloaded method match for 'UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)' has some invalid arguments (CS1502) (Assembly-CSharp)
Error CS1503: Argument 1: cannot convert from 'System.Collections.IEnumerable' to 'System.Collections.IEnumerator' (CS1503) (Assembly-CSharp)
Code:
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public GameObject hazard;
public Vector3 spawnValues;
public int hazardCount;
public float spawnWait;
public float startWait;
void Start () {
StartCoroutine (SpawnWaves ()); //Error appeared here
}
IEnumerable SpawnWaves () {
yield return new WaitForSeconds (startWait);
for (int i = 0; i < hazardCount; i++) {
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
}
}
Answer by TarwaterPV · Jan 05, 2018 at 01:37 AM
The error message is telling you exactly what is wrong, a spelling typo. You are using the wrong type for your method declaration. Use IEnumerator instead of IEnumerable.
Thanks for the help. you must have facepalmed when you saw this. I know I did... but still thanks for the help.
This also solved the error I was getting: cannot convert from System.Collections.IEnumerable to string. Thank you.
You just saved me after 45 $$anonymous$$utes of searching as well. Thank you very much.
Your answer
Follow this Question
Related Questions
ForcedScopedThreadAttach 0 Answers
Destroy a Prefab from an Array? (C#) 2 Answers
Unity Crashes When Clicking Play: Script Error? 1 Answer
ArgumentNullException When using Collider2D.OverlapCollider() 1 Answer
I have an error on a C# script @username 2 Answers