Hi guys,
I have a spawn system in place where it spawns and enemy one after the other which is fine, but after they spawn I want them to move towards me, I know that I have to use the lookat function and get it to move towards my player , but I m struggling where I would put it in my code, I don’t whether I put in a start function or Update here is my code below, please see code below that I have for my enemies spawning: ![]()
using UnityEngine;
using System.Collections;
public class zombiespawn : MonoBehaviour
{
// Spawn location
public Vector3 spawnLocation = Vector3.zero;
// Spawn radius (Gives a bit more randomness factor to the spawn location)
public float spawnRadius = 1.0f;
// Spawn timer (seconds)
public float spawnTimer = 2.0f;
private float spawnTimeRemaining = 5.0f;
// *** test code ***
// The zombie to spawn
public GameObject zombiePrefab = null;
void Awake()
{
spawnTimeRemaining = spawnTimer;
}
void FixedUpdate()
{
spawnTimeRemaining -= Time.deltaTime;
if (spawnTimeRemaining < 0.0f)
{
Vector2 circlePosition = Random.insideUnitCircle * spawnRadius;
GameObject.Instantiate(zombiePrefab, spawnLocation + new Vector3(circlePosition.x, 0.0f, circlePosition.y), Quaternion.identity);
spawnTimeRemaining = spawnTimer;
}
}
}