- Home /
Reduce health constant
Hey, I am making a game in which the health of the character reduces constantly whether it is hit by any obstacle or not. But, if the character is hit by any obstacle, then the health will reduce by some particular amount. The deduction of health will be dependent on the time. I am using C#. if any one can help me with this, it would be a great help. Thanx in advance.
I think you need to explain a bit more what you need. What do you mean by "deduction of health will be dependent on the time"?
Hey @wildex999 Thanx for taking interest. "deduction of health will be dependent on the time" means every frame or every time frame the health will be reduced by some perticular amount.
Answer by ChrisJoosten · Mar 13, 2014 at 01:39 PM
Do you mean something like this?
float Health = 100f;
void Update(){
Health -= 1f * time.Deltatime;
}
void OnCollisionEnter(Collision coll){
if(coll.gameobject.tag == "GameObject You Want"){
Health - 20f;
}
}
Yes @ChrisJoosten, Its exactly i want, By i am not sure if ""Health -= 1f * time.Deltatime;"" will work or not. And the object which will decide how much health to reduce per time frame has to be dynamic. Thanx in advance.
By dynamic do you mean different damage for every object that it's colliding with?
Or do you mean it has to be a different amount of damage for every collision?
No, Dynamic in the sense, it should not be any particular value set in the script. But, it has to be the variable that can be change the value at run time.
Change "1f" to "myVar" and decide for yourself how and when to change it.
something like..
float $$anonymous$$Damage = 1f;
float maxDamage = 50000f; //For Example
float damageDealth;
void Update(){
damageDealth = Random.Range($$anonymous$$Damage, maxDamage);
}
It picks something between them.
Your answer
Follow this Question
Related Questions
How to lose a specific amount of health over time 2 Answers
How would I decrease a variable over time based on distance? 1 Answer
Decrease Health every 5 mins or Time script? 2 Answers
Update not being called every frame 2 Answers
[SOLVED] Need Help "For" loop to execute in specific Intervals 1 Answer