My zombie isn't working and not quite sure what the problem is. I got this script off of a website and it was working before but now it isn't. I know this should be posted on unity answers instead, but it was rejected twice so I'm looking for here. Here is the error: NullReferenceException: Object reference not set to an instance of an object Zombie.FixedUpdate () (at Assets/scripts/Scene5 (level 1)/Zombie.js:18) Here is the script: Code (JavaScript): #pragma strict varVisionDistance:float=200; varMovementSpeed:float=2; varHealth:int=3; functionFixedUpdate(){ // Get the Player object var player :GameObject=GameObject.Find("Player"); var characterController :CharacterController=GetComponent(CharacterController); // Get the position of the Zombie's eyes var eyePosition :Vector3= transform.position; eyePosition.y += characterController.height; // Get the difference between the player and the Zombie positions // This creates a direction vector pointing in the direction of the Player. var lookDirection = player.transform.position - eyePosition; lookDirection = lookDirection.normalized; // Only look for the player or objects that are part of the scenery (terrain, buildings, etc.) var layerMask :int=1<<LayerMask.NameToLayer("Player")|1<<LayerMask.NameToLayer("Default"); // The direction the Zombie will move, defaults to standing still var movementDirection :Vector3=Vector3.zero; // hitInfo will contain information about what the Zombie can see. var hitInfo :RaycastHit; if(Physics.Raycast(eyePosition, lookDirection, hitInfo,VisionDistance, layerMask)){ // If the Zombie can see the Player move toward them. if(hitInfo.collider.gameObject == player){ movementDirection = lookDirection; movementDirection.y =0; movementDirection = movementDirection.normalized; } } // Face and move in the chosen direction if(movementDirection !=Vector3.zero){ transform.rotation =Quaternion.LookRotation(movementDirection,Vector3.up); } characterController.SimpleMove(movementDirection *MovementSpeed); } Any help is appreciated.
First of all use code tags. Code isn't readable without them. As for your error, it's saying there is a null reference. So in your script you're trying to get access to something that doesn't exist
Thanks for the help but I still can't find the problem. If it helps, this is the line of the error (line 14): var lookDirection = player.transform.position - eyePosition;
use code tags, we can't read your code.. http://forum.unity3d.com/threads/using-code-tags-properly.143875/