Hi, i have a gameObject which i control. I tagged it with “Player”.
When a gameObject hits me (a bullet shoot by an enemy), it instantiates an explosion.
My script works perfect when i’m not moving. But when i’m moving, it does detects the collision with something, but not with me (player). Therefore, it does not instantiates the explosion.
This is the code:
var lifeTime = 5.0;
var explosion : Transform;
private var thisTransform : Transform;
function Awake ()
{
thisTransform = transform;
Destroy( gameObject, lifeTime );
}
function OnTriggerEnter( otherObject : Collider)
{
if ( otherObject.gameObject.tag == "Player") /* NOT ENTERING WHEN MOVING*/
{
Debug.Log("hit the Player");
var tempExplosion: Transform;
tempExplosion = Instantiate( explosion, thisTransform.position, Quaternion.identity);
if ( LifeManager.LIVES > 0 )
LifeManager.LIVES--;
//Destroy ( otherObject.gameObject);
}
Destroy ( gameObject );
}
My problem is in the “if” statement. That is not entering when i’m moving.
The weird thing, is that a have a script that does the same when i hit the enemies (only changing the tag), and it works just fine!!
Any ideas?