Full error: NullReferenceException: Object reference not set to an instance of an object
PickUpScript.Update () (at Assets/PickUpScript.js:43)
So this script is meant to pick up and drop items when clicked on. When I pick up the item I get that error. Here’s the script
#pragma strict
var hitObject : GameObject;
var pickupPosition : Transform;
var hold : boolean = false;
var pickableObject : GameObject[];
function Update () {
if(Input.GetMouseButtonDown(1)) {
var hit : RaycastHit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit)) {
hitObject = hit.collider.gameObject;
if (hitObject.tag == "pickUp") {
var kinematic : Rigidbody;
kinematic = hitObject.gameObject.GetComponent (Rigidbody);
hitObject.transform.position = pickupPosition.position;
hold = true;
kinematic.isKinematic = false;
}
}
}
if (hold == true) {
hitObject.transform.position = pickupPosition.position;
}
if (Input.GetMouseButtonUp(1)) {
kinematic.isKinematic = true;
hold = false;
}
if (Input.GetMouseButtonUp(0)) {
Debug.Log ("fire");
}
}
How should I change the script so I don’t get the error?
Thanks in advance.
(Sorry this is like my 5th question today xD)