Water is killing player when enemy enters it

Im trying to make it so that when player enters water I die but when enemy enter it I don’t. I currently have this code which when I enter the water it kills me, and when my enemy enters the water it kills me.

//DamageTrigger.js: A simple, variable damage trigger which can be applied to any kind of object.  
//Change the damage amount in the Inspector. 

var damage: float = 20.0;
var playerStatus : Widget_Status;

function OnTriggerEnter(){
	print("ow!");
	playerStatus = GameObject.FindWithTag("Player").GetComponent(Widget_Status);
	playerStatus.ApplyDamage(damage);
}

@script AddComponentMenu("Environment Props/DamageTrigger")

Need some help here im stumped bad this should be extreemly easy.

1 Answer

1

not sure if I understand what’s going on. I’m guessing Player dies if anything enters the water?

The following is not tested. Just something to nudge you in the right direction…

function OnTriggerEnter (other : Collider) 
{
 var player = GameObject.FindWithTag("Player");
 if(other == player.collider)
 {
    print("ow!");
    playerStatus = player.GetComponent(Widget_Status);
    playerStatus.ApplyDamage(damage);
 }
}

Greetz, Ky.