- Home /
Particle Effect Damage From Box Collider
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);
}
Answer by Adamcbrz · Mar 13, 2012 at 05:26 PM
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
Your answer
Follow this Question
Related Questions
Detect enemy on animation 1 Answer
How to Make Particle Effects Function as a Trigger That Deals Damage 1 Answer
Collision Damage, Hit points and Instantiate 1 Answer
Robot Not Taking Damage 0 Answers
Health Regeneration 2 Answers