I have been following a tutorial series on youtube and I so far I have done everything correct. Until now, I have this error…
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
CollisionDetectionSphereScript.Update () (at Assets/CollisionDetectionSphereScript.js:10)
I sort of understand this means that the script cannot find the item you have selected, or if you have selected one at all.
Here is my code:
var floatAbove : float = 0.1;
var playerCapsuleTransform : Transform;
@HideInInspector
var collisionDetected : boolean = false;
function Update () {
transform.position.x = playerCapsuleTransform.position.x;
transform.position.z = playerCapsuleTransform.position.z;
transform.position.y = playerCapsuleTransform.position.y + ((playerCapsuleTransform.GetComponent(Collider).Height * playerCapsuleTransform.localScale.y) / 2 ) + (transform.localScale.y / 2) + floatAbove;
}
function OnCollisionStay (collision : Collision){
if (collision.transform.tag == "Level Parts")
collisionDetected = true;
}
function OnCollisionExit () {
collisionDetected = false;
}
Now the error is pointing to line 10, but I included the entire script just in case it is a spelling error in another line. I have set the Player Capsule Transform in the Inspector but I still have this error. Please help me resolve this, Thank you.