I am having trouble getting my enemy to move towards the player as of right now it moves away what do I need to change in order to fix it?
public class enemy : MonoBehaviour
{
Transform playerTransform;
UnityEngine.AI.NavMeshAgent myNavmesh;
public float checkRate = 0.001f;
float nextCheck;
// Start is called before the first frame update
void Start()
{
if (GameObject.FindGameObjectWithTag("Player").activeInHierarchy)
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
myNavmesh = gameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if (Time.time > nextCheck)
{
nextCheck = Time.time + checkRate;
FollowPlayer();
}
}
void FollowPlayer()
{
myNavmesh.transform.LookAt(playerTransform);
myNavmesh.destination = playerTransform.position;
}
}