Spawned Objects not appearing

Hello so i’m trying to make a tower defense game, i have the movement from http://forum.unity3d.com/threads/54678-A-Waypoint-Script-Explained-in-Super-Detail!
which works a treat with one object. However i’m trying to spawn more then one object, the below code spawns clones of a enemy prefab i’ve made. However only 1 clone appears and moves in unity. (the waypoint script is attached to a in game object, and the spawn is attached to a separate in game object)

public GameObject spawnedObject;

	int totalCreatures = 18;
	
	int liveCreatures = 0;
	
	float WaveTimeSetup = 20;
	
	float waveTime;
	
	
	
	// Use this for initialization
	void Start () {
	spawn();
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
			
			void spawn(){
			
			   for (int i = 0; i < 10; i++) 

                Instantiate(spawnedObject , transform.position, Quaternion.identity); 
			
 
	}
   
	
	
	
}

from the looks of the code, it would appear that you spawn 10 objects, but all at the same position. Check your hierarchy view and see if there are 10 objets in there, it might just look like 1 in the game view.

Hey, your for loop should look like this:

for(int i = 0; i < 10; i++)  
{
	Instantiate(spawnedObject , transform.position, Quaternion.identity);
}

as your for loop was missing the {}

Hope this helps :slight_smile:

Your code should look something like this:

using UnityEngine;
using System.Collections;

public class HelpingNoobs : MonoBehaviour {
	
	//prefab of the enemy to make
	public GameObject enemyPrefab;
	//used when we instantiate an new enemy
	private GameObject spawnedObject;
	//a reference of all the spawned objects
	private List<GameObject> spawnedObjects;
	//total number of creatures in a level
	private int totalCreatures = 18;
	//number of alive creatures
	private int liveCreatures = 0;
	
	// Use this for initialization
	void Start () {
		//at the start we spawn/initializes all of the enemies for the level
		spawn();
	}
	
	void Spawn() {
		//here we instantiate and save the reference to the enemies in a list
		spawnedObjects = new List<GameObject>();
		
		for(int index = 0; index <= totalCreatures; index++) {
			spawnedObject = Instantiate(enemyPrefab , transform.position, Quaternion.identity);
			spawnedObjects.Add(spawnedObject);
			liveCreatures++;
		}
	}
	
	// Update is called once per frame
	void Update () {
		//in every update we update the list of enemies and mkae them move/die 
		foreach(GameObject enemy in spawnedObjects) {
			//here is where you put your
			//logic to update and move your enemies
			enemy.move();
			if(enemy.Health <= 0)
				enemy.KillMe();
		}
	}
}

Please don’t take offense to the class name.

So, when you level starts this script will execute the start method. This is when we want to spawn the enemies and position them. Then in the update you’ll update every enemy so they will move along the path you supplied. One thing this script does NOT take into account is a staggerness for you enemies. IE most likely all of these enemies will be placed on top of each other since their initial position is the same for each enemy. So, this may explain why you only see one enemy(they are all on top of each other). So to account for this you’ll have to add like a 50pixel offset so each enemy is 50 pixels behind the enemy in front of it.