I have had excruciating tries of finding a solution to this error, but I seem to find nothing. I have a simple cube prefab that spawns, and I want it to be destroyed after a three second delay. I used this:
-----
using UnityEngine;
using System.Collections;
public class Cubes : MonoBehaviour {
public float delay = 0.1f;
public GameObject cube;
public int destroyTimer = 3;
void Start () {
InvokeRepeating("Spawn", delay, delay);
Destruction();
}
void Spawn () {
Instantiate(cube, new Vector3(Random.Range(-6, 6), 10, -2), Quaternion.identity);
}
void Destruction() {
yield return new WaitForSeconds(destroyTimer);
Destroy(gameObject);
}
}
-----
I am getting the same stupid error over and over, no matter what I do. Here it is:
"`Assets/Cubes.cs(18,14): error CS1624: The body of `Cubes.Destruction()' cannot be an iterator block because `void' is not an iterator interface type`"
Can anyone help me out?
Thanks in advance!
↧