/// Decrements the health by the specified amount /// Returns true if the entity dies on hit public bool Hit(float damage) { float newHealth = this.health - damage; if (newHealth > 0) { // play sound effect if (ValueModifier.TryGetModifier(this).randomSounds) { SoundManager.i.SetPitch("Quack", Random.Range(0.75f, 0.9f)); SoundManager.i.PlayOnce("Quack"); SoundManager.i.SetPitch("Quack", 1); } else { SoundManager.i.PlayOnce(this.hurtSoundName); } // set health values this.health = newHealth; return(false); } else { health = 0; if (destroyOnDeath) { Destroy(gameObject); } return(true); } }
void Start() { // apply health modifier maxHealth *= Mathf.Max(ValueModifier.TryGetModifier(this).health, ValueModifier.MIN_VALUE); // initialize values health = maxHealth; }
protected override void ThrottledUpdate() { WeaponType left = ValueModifier.TryGetModifier(this).leftWeapon; if (left != previousLeft) { previousLeft = left; SwitchWeapon(left, LeftHand); } WeaponType right = ValueModifier.TryGetModifier(this).rightWeapon; if (right != previousRight) { previousRight = right; SwitchWeapon(right, RightHand); } }
void LateUpdate() { // update modifier this.modifier = ValueModifier.TryGetModifier(this); }
void FixedUpdate() { float speed = this.speed * ValueModifier.TryGetModifier(this).speed; transform.Translate(movement * speed * Time.fixedDeltaTime); //Move player based on input. }