Spawning more prefabs than needed.

So, my game was running REEEALLLY slow and i couldn’t figure out why, when i was only spawing 4 enemys. Then i figured out i was spawning 16 enemys. So what is wrong with this code, that makes it spawn 4 instead of one? I’ve looked through it, but i’m just learning how to use messages so can anyone help?

SpawnMessage

using UnityEngine;
using System.Collections;

public class SpawnMessage : MonoBehaviour {

	// Use this for initialization
 public IEnumerator Start() {
        print(Time.time);
        yield return new WaitForSeconds(5);
		Messenger.Broadcast("spawn type1");
}
	
	// Update is called once per frame
	void Update () {
	
	}
}

CreateMob

using UnityEngine;
using System.Collections;



public class CreateMob : MonoBehaviour {
	public Transform thePrefabToInstantiate;

	void OnEnable()
{
Messenger.AddListener("spawn type1",Spawn1);
}

void OnDisable() // to avoid reference problem on LoadLevel
{
Messenger.RemoveListener("spawn type1",Spawn1);
}

void Spawn1()
{
Instantiate(thePrefabToInstantiate, transform.position,transform.rotation);
}
}

Anyone? Bump

Where are you triggering this event? If its in collision events that may be the reason.

Add a log to the object which spawns this. I haven’t used the messaging system, i hear its quite slow so you might want to look into delegates for this.

A quick hack for this might be to store the last time a mob was spawned and it time is greater than the last time spawn another.

Well Literally it spawns the enemies when the scene starts, so no collision problems. I just can’t put my finger on why it’s spaning four enemies at the spawn point instead of one

Anyone?