I’m creating a topdown shooter but with the camera immovable.
i have a location (empty game object) im trying to spawn the enemy out of (which is in the center of the scene)
i want them to spawn and translate outwards but everytime they spawn it’s randomized in direction.
i was working with a change in spawn time every time but couldn’t get the rotation done as i have problem working with the “quarternion” section of the script? It confuses me how to work with that area.
Here is my script:
using UnityEngine;
using System.Collections;
public class EnemySpawn : MonoBehaviour {
public GameObject enemyToSpawn = null;
public float spawnDelayMin = 5.0f;
public float spawnDelayMax = 8.0f;
private float _nextSpawnTime = 0.0f;
private GameObject _spawnedEnemy = null;
private Transform _t = null;
// Use this for initialization
void Start ()
{
_t = transform;
}
// Update is called once per frame
void Update () {
if(_spawnedEnemy == null && Time.time > _nextSpawnTime)
{
_nextSpawnTime = Time.time + Random.Range(spawnDelayMin, spawnDelayMax);
_spawnedEnemy = Instantiate (enemyToSpawn, _t.position + new Vector3(Random.Range (-100,0,0), Quaternion.identity) as GameObject;
}
}
}