//For when the enemy object takes damage public void takeDamage(int damage, bool crit, GameObject source) { //Debug.Log (gameObject + " takes " + damage + " damage."); if (Random.value < chanceSpawnOnHit) { ObjectPooler.Instance.GetObject(enemy.ObjectPoolIndex, true, spawnpoint.gameObject.transform.position, Quaternion.Euler(new Vector3(0f, Random.Range(0, 360), 0f))); } if (healthBar == null) { InstantiateHealthBar(); } health -= damage; healthBarImage.fillAmount = (float)health / startingHealth; float lerp = (float)health / (float)startingHealth; healthBarImage.color = Color.Lerp(Color.red, Color.magenta, lerp); DamagePopUp.CreateDamagePopUp(damage, gameObject, crit); if (clip_takeDamage != null) { ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform); } if (health <= 0) { // Debug.Log ("dead"); StartCoroutine(spawn()); Die(); } }
//For when the enemy object takes damage public void takeDamage(int damage, bool crit, GameObject source) { //Debug.Log (gameObject + " takes " + damage + " damage."); if (healthBar == null) { InstantiateHealthBar(); } health -= damage; healthBarImage.fillAmount = (float)health / startingHealth; float lerp = (float)health / (float)startingHealth; if (lerp <= .5f) { lerp *= 2f; healthBarImage.color = Color.Lerp(Color.red, Color.yellow, lerp); } else if (lerp > .5f) { lerp -= .5f; lerp *= 2f; healthBarImage.color = Color.Lerp(Color.yellow, Color.green, lerp); } DamagePopUp.CreateDamagePopUp(damage, gameObject, crit); if (clip_takeDamage != null) { ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform); } if (health <= 0) { if (anim != null) { // Debug.Log ("animation time"); anim.SetTrigger("Die"); // Debug.Log (anim.GetCurrentAnimatorClipInfo (0).Length); } // Debug.Log ("dead"); ReturnPlayerData(source); Die(); } else if (clip_takeDamage != null) { ObjectPooler.Instance.PlayAudioSource(clip_takeDamage, mixerGroup, pitchMin, pitchMax, transform); } }