Spawning with C#

i’m trying to get the effect of snakes dropping from an unseen ceiling. I need to use c# as thats what my health script is wirtten in. The only problem is… nothing happens. I get the error, “Awake can not be a co routine” heres my code. Do you see the problem?

using UnityEngine;
using System.Collections;

public class Spawn : MonoBehaviour {
 	public Transform prefab;
	 
	public IEnumerator Awake() {
		   Instantiate(prefab);
	yield return new WaitForSeconds(5);
     
    }
}

try this :

using UnityEngine;
using System.Collections;

public class Spawn : MonoBehaviour {

 	public Transform prefab;

	public IEnumerator Do() {
          yield return new WaitForSeconds(5);     
          // code to be executed after 5 secs
        }

	public void Awake() {
             Instantiate(prefab);
	     yield return StartCoroutine("Do");
     
        }
}

Do you want the instantiation to happen constantly (every five seconds) throughout your game? If so, just use InvokeRepearting, ie:

public void Awake ()
{
    InvokeRepeating ("Spawn", 0, 5)
}

private void Spawn ()
{
    Instantiate (prefab);
}

The error means just what it says. Returning an IEnumerator and using yield makes the function a coroutine, and Awake isn’t allowed to be a coroutine.

Thanks. And how would i implement the spawning of the snake to be at the spawn points position?

GameObject[] spawnpoints = GameObject.FindGameObjectsWithTag ("SpawnPoint");

Transform spawnpoint = spawnpoints[Random.Range(0, spawnpoints.Length)].transform;

Instantiate(prefab ,spawnpoint.position, spawnpoint.rotation, 0);

Just make sure your spawnpoints are tagged and this should work fine.