I am working on an enemy spawn script that needs some adjustments/polishing. I want to make zombies spawn in front of my “guy/player”. After they spawn in front of him, I know how to do the rest. Just the spawning in front part is the only thing I am confused on. I was using a Invoke repeating() to make zombies spawn at a certain spot but now I want them to span directly in front of my player.I know that I will have to get my “players” position but I don’t know what to do from there. Thanks for the help and your time.(feel free to rewrite my code or make any helpful adjustments)
here is my code:
var SpawnObject : GameObject;
var player : Transform;
private var SpawnStartDelay : float = 0;
var SpawnRate : float = 1.0;
private var amountOfE : float = 0;
var maxAmount : float = 10;
var distance = 15;
var playerCloseEnough = false;
function Start()
{
InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate);
}
// Spawn the SpawnObject
function Spawn()
{
if(playerCloseEnough == true)
{
amountOfE++;
Instantiate(SpawnObject, transform.position, transform.rotation);
}
else{}
}
function Update()
{
if(amountOfE == maxAmount)
{
CancelInvoke("Spawn");
Destroy(this.gameObject);
}
else{}
if(Vector3.Distance(transform.position, player.position) < distance)
{
playerCloseEnough = true;
}
}