I have been working on 'TheLorax’s Jump Start Tutorial, (http://forum.unity3d.com/viewtopic.php?t=28433) and i am on the final part (explosions when the enemy crashes into the player) and at this point the game pauses and it says…
'NullReferenceException: The prefab you want to Instantiate is Null.
var playerSpeed : int;
var playerLives : int;
static var playerScore : int;
var bullet : Rigidbody;
var explosion: Transform;
function Update () {
//amount to move playerSpeed
amtToMove = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
//move/translate the playerSpeed
transform.Translate(Vector3.right*amtToMove);
//Fire weapon
if(Input.GetKeyDown("space")){
var tempBullet: Rigidbody;
tempBullet = Instantiate(bullet, transform.position, transform.rotation);
}
}
function OnGUI(){
GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);
GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);
}
function OnTriggerEnter(otherObject:Collider){
if(otherObject.gameObject.tag == "enemy"){
otherObject.gameObject.transform.position.y = 7;
otherObject.gameObject.transform.position.x = Random.Range(-6,6);
var tempExplosion: Transform;
tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
playerLives --;
}
}
Apparently the error is at line 47,anyone got any ideas on a fix, as everything has been working up until now, and Im pretty close to completeting it.
tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
Hope someone can help,
Many Thanks.
Soldier_Jaqqson