This question was
closed Mar 23, 2016 at 08:08 AM by
ash_richie for the following reason:
The question is answered, right answer was accepted
Question by
ash_richie · Feb 07, 2016 at 09:17 AM ·
c#
i have a problem with coding NullReferenceException: Object reference not set to an instance of an object EnemyController.Update () (at Assets/EnemyController.cs:14)
here's my code
using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour {
NavMeshAgent nav;
Transform player;
Animator controller;
// Use this for initialization
void awake () {
nav = GetComponent <NavMeshAgent> ();
player = GameObject.FindGameObjectWithTag ("player").transform;
controller = GetComponentInParent<Animator> ();
} // Update is called once per frame
void Update () {
nav.SetDestination (player.position);
controller.SetFloat ("speed", Mathf.Abs (nav.velocity.x) + Mathf.Abs (nav.velocity.z));
}
}
the problem
NullReferenceException: Object reference not set to an instance of an object
EnemyController.Update () (at Assets/EnemyController.cs:14)
plz help
Comment
Best Answer
Answer by Jessespike · Feb 07, 2016 at 09:49 AM
Awake() is misspelled. First letter needs to be uppercase.
http://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
@jessespike thanks a lot you helped me a lot thnx thnx thnx!!!!