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