- Home /
This question was
closed Jun 05, 2014 at 07:41 AM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
HahnSolo157 · Jun 05, 2014 at 06:32 AM ·
rigidbodyobject
[Solved]Object reference not set to instance of object in OnTriggerEnter
The game runs, but every time an enemy spawns, I get one of these errors on line 32, or the second "if" statement in the OnTriggerEnter function. The Sniper Rifle bullets don't register hitting the enemy, and I think this error has something to do with it. I have no idea why I get this error though.
var health : float = 100.00;
var SpawnPoint : Transform;
var Blood : Rigidbody;
var Dead : Rigidbody;
var Bullet : GameObject;
var SniperBullet : GameObject;
function Update() {
Bullet = GameObject.Find("Bullet 1(Clone)");
SniperBullet = GameObject.Find("Bullet 2(Clone)");
if(health <= 0.0)
Death();
}
function Death() {
var Boom : Rigidbody;
Boom = Instantiate(Dead, SpawnPoint.position, SpawnPoint.rotation);
Destroy(gameObject);
Points.Score += 10;
}
function OnTriggerEnter(other: Collider) {
var Spawn : Rigidbody;
if(other.gameObject.tag == "Bullet")
{
health -= 25.0;
Points.Score += 5;
Spawn = Instantiate(Blood, SpawnPoint.position, SpawnPoint.rotation);
Destroy(Bullet);
}
if(other.gamObject.tag == "SniperBullet")
{
health -= 100.0;
Points.Score += 5;
Spawn = Instantiate(Blood, SpawnPoint.position, SpawnPoint.rotation);
}
}
Comment
Best Answer
Answer by Bunnybomb7670 · Jun 05, 2014 at 06:41 AM
You spelled it wrong. Line 32 is :
if(other.gamObject.tag == "SniperBullet")
but it should be :
if(other.gameObject.tag == "SniperBullet")