NullReferenceException: Object reference not set to an instance of an object (57533)

This is my gun script my gun is not following the camera on my character i wonder whats the problem here.. can anyone please help me..

var cameraObject : GameObject;
@HideInInspector
var targetXRotation : float;
@HideInInspector
var targetYRotation : float;
@HideInInspector
var targetXRotationV : float;
@HideInInspector
var targetYRotationV : float;

var rotateSpeed : float= 0.3;
var holdHeight : float= -0.3;
var holdSide : float= 0.3;
function Update () {
transform.posotion = cameraObject.transform.position+(Quaternion.Euler(0,targetYRotation,0)*Vector3(holdSide,holdHeight,0));
targetXRotation=Mathf.SmoothDamp(targetXRotation,cameraObject.GetComponent(MouseLook).xRotation, targetXRotationV, rotateSpeed);
targetYRotation=Mathf.SmoothDamp(targetYRotation,cameraObject.GetComponent(MouseLook).yRotation, targetYRotationV, rotateSpeed);
transform.rotation=Quaternion.Euler(targetXRotation,targetYRotation,0);
}

the whole error message is:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
Gun.Update () (at Assets/MyScripts/Gun.js:16)

use the code sample button, your code is not readable here ... You can also tell us at what line the problem is. When you double clic on the error, it shows you where the problem occured.

1 Answer

1

Check in the inspector if the cameraObject is valued. If not, drag and drop the camera game object in the field.

There also is in the first line in the Update method transform.posotion, change with transform.position