- Home /
GetComponent error: Object Reference not set to an instance of an object.
So, I have this big block that is supposed to descend and crush the player when the player steps on a trigger. The console is returning the error "NullReferenceException: Object reference not set to an instance of an object. bigBlockTrigger.OnTriggerEnter(UnityEngine.Collider other)(at Assets/Scrips/bigBlockTrigger.js:19)"
Here are the two scripts (JAVASCRIPT):
(Code on trigger, "bigBlockTrigger")
#pragma strict
function Start () {
}
function Update () {
}
function OnTriggerEnter(other : Collider) {
if(other.tag == "Player")
{
print("Woohoo");
var Moving: bigBlockScript = GetComponent(bigBlockScript);
Moving.isMoving = true;
}
}
And (Code on Block, "bigBlockScript")
#pragma strict
public var isMoving : boolean = false;
public var speed: int = 2;
function Start () {
}
function Update () {
if(isMoving == true){
transform.position -= transform.up * speed * Time.deltaTime;
}
}
Please help :)!
Answer by morgan23 · May 13, 2014 at 05:30 PM
Try GameObject.findwithtag instead on your first script see if that helps.
Your answer
Follow this Question
Related Questions
Can't reference boolean in another script 3 Answers
(Yet another) Accessing array in another script - ref or copy? 1 Answer
farming game with replanting problem 2 Answers
Reference script on Behaviour is Missing, but IT'S NOT MISSING 0 Answers
Change a Variable with another script not working (C#) 4 Answers