Hi all,
I have a scene setup with a player and some spawnpoints dotted around to spawn my enemies.
I also have a navmesh.
The spawn script chooses a spawn point at random and instantiates an enemy prefab at that point.
What I am trying to do is simply get my enemies to follow my player.
Here is my script to make the enemy prefab follow the player.
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform M_Player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
GetComponent<NavMeshAgent>().destination = M_Player.position;
}
}
If I get rid of the spawn points and add the enemy directly to my scene the script works fine.
If I use spawn points, I can’t drag my player object onto the transform slot of my script.
How do I add my players transform to the script when my enemy is still a prefab in the inspector and not part of the game scene?