Hi, I am trying to make a gameobject follow the player once the player enters a sphere collider on the gameobject, however instead of following the player when it collides with the trigger, it follows the player from the second I start the test run.
I am at a loss. Any tips would be appreciated.
using UnityEngine;
using System.Collections;
public class DetectPlayer : MonoBehaviour {
NavMeshAgent agent;
public Transform target;
public GameObject Player;
public bool follow = false;
// Use this for initialization
void Start () {
agent = GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
if (follow == true) {
agent.SetDestination (target.position);
}
}
void OnTriggerEnter (Collider col) {
//checking if player collides with trigger
if (col.GetComponent<Collider>().tag == Player.tag) {
follow = true;
}
}
}