- Home /
Duplicate Question
Enemies Problem
Can you help me with this script it says i have Object reference not set to an instance of an object problem when im in the game and kill my enemy here's the code
#pragma strict
private var fall : boolean;
var Player : GameObject;
var spawnPoint : Transform;
var stomp : boolean;
function Update () {
if(stomp){
transform.position.z = 4;
transform.localScale.y /= 2;
fall = true;
gameObject.GetComponent(PlatformMover).step = 0.0;
stomp = false;
}
if(fall){
transform.position.y -= 0.05;
}
if(transform.position.y < -25){
Destroy(gameObject);
}
}
function OnTriggerEnter(other : Collider){
if(!stomp){
if(other.tag == "Player"){
Destroy(other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
var sf = Camera.main.GetComponent(SmoothFollow2);
sf.target = P.transform;
}
}
}
Code the exception message from the console. There are a lot of places objects/properties of objects are referenced in your code, having a null reference and not giving the exception message is not helpful generally, i've formatted your code.
Answer by Graham-Dunnett · Jul 10, 2014 at 10:46 AM
This question has been asked over 700 times. http://answers.unity3d.com/questions/topics/nullreferenceexception.html
Follow this Question
Related Questions
hide game object problems 2 Answers
Missing Method Exception and Null Reference Exception 3 Answers
getting udp package info inside unity (GlovePIE) 0 Answers
Why are my assets not showing up in the Scene panel? 2 Answers
In-Game Shop Problems 1 Answer