1

I tried everything, i baked navigation mesh manually but still it doesn't work. If you know how to solve that problem please help me.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyController : MonoBehaviour {

    public float lookRadius = 10f;
    Transform target;
    public NavMeshAgent agent;

    void Start () {
        target = PlayerManager.instance.player.transform;
        agent = GetComponent<NavMeshAgent> ();
        if (agent.isOnNavMesh == false)
            Debug.Log ("NOOOOOO");
    }

    void Update () {
        float distance = Vector3.Distance (target.position, transform.position);
        if (distance <= lookRadius){
            agent.SetDestination (target.position);
        }
    }

    void OnDrawGizmosSelected() {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, lookRadius);
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
Burak Fidan
  • 23
  • 1
  • 8
  • 1
    Your agent might be disabled. There is a checkbox in the upper-left corner of the component in the editor. Alternatively you could try to set agent.enabled = true; after the GetComponent. – Tobias Theel Dec 22 '17 at 17:44
  • Tried it but the result is the same. if (agent.isOnNavMesh == false) Debug.Log ("NOOOOOO"); it keeps printing NOOOOO – Burak Fidan Dec 23 '17 at 19:41

0 Answers0