I’ve got a problem about OnTriggerEnter;
#pragma strict
static var health : int = 100;
var bullet : GameObject;
var explosion : GameObject;
function Start () {
bullet = GameObject.FindWithTag("Bullet");
}
function OnTriggerEnter (bulletCol : Collider)
{
if(bulletCol.gameObject.name == bullet.name)
{
health -= 50;
}
}
function Update () {
if(health < 5)
{
Instantiate(explosion, transform.position, transform.rotation);
}
}
This is my code, but when a bullet hits, it doesn’t affect. I tagged bullet prefab as “Bullet” but nothing happens. so what can i do ?