# How is calculate this?

 0 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 19hope is understandable and do not did a mess more ▼ asked Aug 11 '12 at 10:20 AM Ingen 145 ● 3 ● 11 ● 19 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Aug 11 '12 at 10:55 AM zyzyx 226 ● 1 ● 3 thanks a lot Aug 11 '12 at 11:12 AM Ingen add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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!"); } } more ▼ answered Aug 11 '12 at 11:13 AM aldonaletto 41.5k ● 16 ● 42 ● 197 thank you very much Aldo,I tried to do this but without find the right way, I need too much learnthank you again Aug 11 '12 at 11:38 AM Ingen add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: