Mulitple spawn points with random seed.

I'm trying to write a Javascript that will spawn X-amount of enemies from 4 different platforms. They will need to spawn at random times rather than all at once. I'm guessing that I will need to use a Random class to divide up the enemyPrefabs, and at different times as well. The level is finished when all enemies are killed. The tutorials I've found only deal with spawning one enemy dependent on range from PlayerObject.

I'm thinking of having a Parent GameObject (SpawnPoints) with the script and each of the spawn points (spawn1-4) attached as children.

This is my initial thinking for the variables:

var enemyPrefab : GameObject;
var maxEnemies : int;

var spawn1 : transform;
var spawn2 : transform;
var spawn3 : transform;
var spawn4 : transform;

Any links to tutorials or other help is appreciated.

Here's the code I came up with that will let you set up Random Enemies, spawnPoints, maxEnemies and min/max time to wait between each respawn.

This works great but I have one hitch to figure out. Sometimes when the Enemy is instantiated, the model will randomly default to the base T-Pose with no components. Furthermore, any other instances spawned at that spawnPoint will also be locked in the base T-pose, overlapping. They have enough time to clear each other's location/spawnPoint so that's not it either.

Any ideas?

// Add this script to a Parent GameObject of the spawnPoints.
// Note: enemyPrefab will have an AI script attached which will already Tag the Player object 
// so it won't be needed here.

var spawnPoints : Transform[];  // Array of spawn points to be used.
var enemyPrefabs : GameObject[]; // Array of different Enemies that are used.
var amountEnemies = 20;  // Total number of enemies to spawn.
var yieldTimeMin = 2;  // Minimum amount of time before spawning enemies randomly.
var yieldTimeMax = 5;  // Don't exceed this amount of time between spawning enemies randomly.

function Start()
{
    Spawn();
}

function Spawn() 
{ 
   for (i=0; i<amountEnemies; i++) // How many enemies to instantiate total.
   {
      yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));  // How long to wait before another enemy is instantiated.

      var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)]; // Randomize the different enemies to instantiate.
      var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];  // Randomize the spawnPoints to instantiate enemy at next.

      Instantiate(obj, pos.position, pos.rotation); 
   } 
}  

I just added a component like this to a game I'm working on, and I'll explain what we did.

Create a "Spawner" game object, and add various spawn points as children, placing them in the world wherever you want them. Inside of the "Spawner" object, you'd want to do something like this:


// Place this code inside a loop or function
// whenever you want the object to spawn at a random location.
Transform[] spawnPoints = GetComponentsInChildren(typeof(Transform)) as Transform[];
Instantiate(myGameObjectPrefab, spawnPoints[Random.Range(0, spawnPoints.Length)], Quaternion.identity);

That gets all the transform components inside all of the children (which are your spawn points), and then instantiates a prefab at one of the spawn points randomly. Be sure to set the `myGameObjectPrefab` variable as a public variable in your script, and then set its value using the Inspector in the editor...something like this:


public GameObject myGameObjectPrefab;

oke, i tried some things.
this one was the best working.

using UnityEngine;
using System.Collections;

public class PlayerMove : MonoBehaviour {

	public int Speed;
	public float Jumpheigt;
	public bool Jump = false;
	public AnimationClip walk;
	public int totalScore;	
	
	private camerascript CS;	
	private float rote = 90;
	private bool checkrote;
	private Transform currentpos;
	
	void Start()
	{
		
		CS = GameObject.Find("Camera").GetComponent<camerascript>();
		
	}
	
	
	
	void FixedUpdate () 
	{
		if(Input.GetKey(KeyCode.D))
		{
			
			rigidbody.AddForce(Vector3.back * Speed);
			animation.Play();
			
			if(Input.GetKey(KeyCode.W))
			{
				
				rigidbody.velocity = Vector3.up * Jumpheigt;
				
			}
			
		}
		else if(Input.GetKey(KeyCode.A))
		{
			
			rigidbody.AddForce(Vector3.forward * Speed);
			animation.Play();
			
			if(Input.GetKey(KeyCode.W))
			{
				
				rigidbody.velocity = Vector3.up * Jumpheigt;
				
			}
			
		}
		else if(Input.GetKeyDown(KeyCode.W))
		{
			
			rigidbody.velocity = Vector3.up * Jumpheigt;
			animation.Play();
			
		}
		else
		{
			
			animation.Stop();
			return;
			
		}
		
	}
	
	void Update()
	{
		
		if(Input.GetKeyDown(KeyCode.D))
		{
			
			if(checkrote == true)
			{
				
				transform.Rotate(transform.rotation.y, rote, Time.deltaTime);
				CS.setOn = true;
				checkrote = false;
				
			}
			
		}
		else if(Input.GetKeyDown(KeyCode.A))
			
		{
			if(checkrote == false)
			{
				
				transform.Rotate(transform.rotation.y, -rote, Time.deltaTime);
				CS.setOn = false;
				checkrote = true;
				
			}
			
		}
		else
		{
			
			return;
			
		}
		
	}
	
	public void score(int score)
	{
		
		totalScore = totalScore + score;
		Debug.Log("je hebt : " + totalScore + " aan punten");
		
	}
}

but it still won’t work properly

please some advice

thanx a lot