- Home /
Question by
importguru88 · Aug 20, 2016 at 08:37 AM ·
spawnspawningspawning problemsspawnpoints
How do I spawn more the one spawnpoints ramdomly in my scene / Spawning problems
I am have a problem . I currently have two spawnpoints in my scene. When I play the scene one enemy ai spawns . The other enemy ai's won't spawn and then will spawn but don't move to the player they just . I don't know what is going on with that . I need to fixed to problem . Here is my script :
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : MonoBehaviour {
public GameObject enemy;
public Transform [] spawnPoints;
public float spawnTime = 5f;
public Vector3 spawnValues;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Update () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length); for( int spawnCount = spawnPoints.Length - 1 ; spawnCount >= 0 ; --spawnCount )
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z) ) ; // <= here
}
}
Comment