Hi stackoverflow's Members, This my first question...
I want to spawn Enemies at random spawn points without overlapping. So, I'm checking that if the spawn point is used then don't use that spawn point, if it's not then continue... I've an empty gameObject which contains all spawnPoints for enemy. I've assigned the script to that empty gameobejct.
I tried to use Transform as a List for Spawn points but unfortunately, it didn't work. If you can convert this from Vector3 to Transform then, it'll be good. I tried to convert this in Transform but I got so many error. I did try, but, it didn't work as expected.
You can check that script here: Transform error script
I got these errors: Transform errors
Now, The script which I'm working on is as follow:
using UnityEngine;
public GameObject enemy; //my enemy
public float spawnTime = 3f; //spawn after 3 sec
public List<Vector3> spawnPoints = new List<Vector3> (); //Vector3 positions of spawnpoints.
public float distance; //distance from the spawnPoints
void Start ()
{
//spawnRandom ();
InvokeRepeating ("spawnRandom", spawnTime, spawnTime); //Call this fucntion after 3sec.
}
public Vector3 spawnRandom(){
Vector3 newSpawnPoint; //new spawn point
Vector3 random = UnityEngine.Random.insideUnitSphere * distance;
newSpawnPoint = new Vector3 (random.x, 0, random.z);
newSpawnPoint += transform.position;
if (!spawnPoints.Contains (newSpawnPoint)) {
return newSpawnPoint;
spawnPoints.Add (newSpawnPoint);
int spawnIndex = Random.Range (0, spawnPoints.Count);
Instantiate (enemy, spawnPoints [spawnIndex].normalized, Quaternion.identity); //Spawn randomly
} else {
return Vector3.zero;}}
The problem is enemy is not spawning!
Aucun commentaire:
Enregistrer un commentaire