- Home /
NullReferenceException : Object reference not set to an instance of an object
Im trying to access a variable from another script, but I get this error. What am I doing wrong?
public var gravity : boolean;
public var Force : float;
private var onTop : boolean;
public var Player: Transform;
private var PlayerScript : CharacterMotor = Player.GetComponent(CharacterMotor);
function Update () {
if(gravity){
if(onTop){
PlayerScript.Gravity -= Force;
}
}
onTop = false;
}
function OnTriggerStay(other : Collider){
if(other.tag == "Player"){
onTop = true;
}
}
Comment
Verify that 'Player' is being initialized in the Inspector. If it is, go to the Hierarchy and in the upper right search box, type in the class name of the above script to see if it is attached at more than one place.