I have this script attached to my particle effect collider box I built and as you pass though it you take damage. What I am needing is that if you pass though it you take damage but if u stay in it you contiue to take damage.
This is my damage code:
//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 = 15.0;
var playerStatus : Player_Status;
function OnTriggerEnter(){
print("ow!");
playerStatus = GameObject.FindWithTag("Player").GetComponent(Player_Status);
playerStatus.ApplyDamage(damage);
}
David,
You can just set the variable playerStatus on enter and unset it on exit. Then have an Update function call the apply damage method
function OnTriggerEnter()
{
playerStatus = GameObject.FindWithTag("Player").GetComponent(Player_Status);
}
function Update()
{
if(playerStatus != null)
playerStatus.ApplyDamage(damage);
}
function OnTriggerExit()
{
playerStatus = null;
}
FYI, you might want to either lower the amount of damage taken or have a delay on how often to apply damage. Another thought is you could apply an initial damage of 15 when you enter the collider and then have a different amount you deduct for the time you spend in the collider.
Hope this helps,
Adam