Ingen
1
Hello
I need to understand how this is calculate,I have a DamageSystem.js for all type of damage, with inside
var HEALT = 100;
.....
function FallDamage(Damage :float ){
HEALT -= Damage;
HEALT --;
Debug.Log("I'm falling");
}
and a send message on FPS Walker
function FallingDamageAlert (fallDistance : float) {
FindObjectsOfType(Damage_System);
if (fallDistance >= 15)
{
gameObject.SendMessageUpwards ("FallDamage",4,SendMessageOptions.DontRequireReceiver);
}
if (fallDistance >= 20)
{
gameObject.SendMessageUpwards ("FallDamage",19,SendMessageOptions.DontRequireReceiver);
}
Debug.Log ("Ouch! Fell " + fallDistance + " units!");
}
My questions is, I want remove 5 for fallDistance >= 15 + 20 for fallDistance >= 20, in total 25,
but need write 4 and 19.
Why will be removed 5 health point for if (fallDistance >= 15), and 20 for if (fallDistance >= 20), if I write 4 and 19
hope is understandable and do not did a mess
zyzyx
2
HEALT -= Damage; // is the same as HEALT = HEALT - Damage;
HEALT --; // is the same as HEALT = HEALT -1;
You first subtract the actual damgage from your health then you subtract additional 1.
As @zyzyx said, you’re actually applying Damage+1. You could make your code more clear by just subtracting Damage from HEALT, and improve the messaging by using a single SendMessageUpwards (SendMessage functions are a bit slow):
function FallDamage(Damage :float ){
HEALT -= Damage;
Debug.Log("I'm falling");
}
// send message:
...
function FallingDamageAlert (fallDistance : float) {
...
if (fallDistance >= 15){ // if fallDistance >= 15...
var damage: float = 5; // assume damage 5...
if (fallDistance >= 20){ // but if it's >= 20...
damage = 25; // change damage to 25
} // apply the specified damage
gameObject.SendMessageUpwards ("FallDamage", damage, SendMessageOptions.DontRequireReceiver);
Debug.Log ("Ouch! Fell " + fallDistance + " units!");
}
}