Search Unity

NavMeshAgent Not Identifying as a Class in C#

Discussion in 'Scripting' started by SlKL, Dec 12, 2016.

  1. SlKL

    SlKL

    Joined:
    Feb 4, 2016
    Posts:
    2
    whenever I uses NavMeshAgent in my C# code it won't Identify itself. But if I use using UnityEngine.AI it will Identify itself but it won't work in my game because the character then won't move. Any Help is appreciated
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    5,433
    Your "Start()" function is spelled as "start()" and will never be called by Unity.

    Upper/lower case is critical in software engineering.If you are in doubt, always copy/paste the built-in delegate methods from the reference Unity documentation to get the spelling and case correct.
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,468
    Or use the Implement MonoBehaviour Method from the context menu in VS :)
     
    TaleOf4Gamers likes this.
  4. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    178
    You have to call UnityEngine.AI - it's the namespace the NavMeshAgent lives in. If the character isn't moving, it's not becuase you are using that namespace, it's because you aren't doing something else. You cannot call NavMeshAgent without using it's parent namespace.

    And yes, Start() needs to be in caps.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    5,433
    NOTE: the UnityEngine.AI namespace is a Unity 5.5 and higher namespace only.

    In Unity 5.4 and earlier, NavMeshAgent is just in the basic UnityEngine namespace.
     
    pashabica likes this.
  6. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    178
    True - I inferred that he was on 5.5 since he said it only worked with UnityEngine.AI.
     
    Kurt-Dekker likes this.
  7. SlKL

    SlKL

    Joined:
    Feb 4, 2016
    Posts:
    2
    Yep that was the problem + the Start() , I went down from 5.5 to 5.4 and it now works. Thank you :)
     
unityunity