/// <summary> /// The entity takes damage from a known source. /// </summary> /// <param name="source">The source GameObject damaging the entity.</param> /// <param name="reciever">The entity collider involved in the collision.</param> /// <param name="damage">Ammount of damage to be taken.</param> /// <param name="direction">Incoming damage direction. Axis represented in clockwise order: 0-Forward, 1-Left, 2-Back, 3-Right.</param> /// <param name="pushForce">Force applied to the entity in the specified direction.</param> /// <param name="stunForce">Stun duration applied to the entity.</param> /// <returns>True if enemy was damaged, otherwise false.</returns> public override bool RecieveAttack(GameObject source, Collider reciever, float damage = 0, int direction = 0, float pushForce = 0, float stunForce = 0) { if (reciever.gameObject == bodyHitbox) { if (((direction + 2) % 4) == lookingDirection) { Damage(damage / 10, direction, 0, 0); SoundManager.GetInstance().Play(blockClip); FloatingNumberController fnc = PoolManager.poolManager.GetPoolInstance(floatingNumberPrefab).GetComponent <FloatingNumberController>(); fnc.number = -(int)damage / 10; fnc.textColor = Color.gray; fnc.transform.position = transform.position + Vector3.up * .5f + Vector3.right * UnityEngine.Random.Range(-.1f, .1f) + Vector3.forward * UnityEngine.Random.Range(-.1f, .1f); fnc.Init(); } else { Damage(damage, direction, pushForce, stunForce); SoundManager.GetInstance().Play(hurtClip); FloatingNumberController fnc = PoolManager.poolManager.GetPoolInstance(floatingNumberPrefab).GetComponent <FloatingNumberController>(); fnc.number = -(int)damage; fnc.textColor = Color.red; fnc.transform.position = transform.position + Vector3.up * .5f + Vector3.right * UnityEngine.Random.Range(-.1f, .1f) + Vector3.forward * UnityEngine.Random.Range(-.1f, .1f); fnc.Init(); } return(true); } return(false); }
/// <summary> /// The entity takes damage from a known source. /// </summary> /// <param name="source">The source GameObject damaging the entity.</param> /// <param name="reciever">The entity collider involved in the collision.</param> /// <param name="damage">Ammount of damage to be taken.</param> /// <param name="direction">Incoming damage direction. Axis represented in clockwise order: 0-Forward, 1-Left, 2-Back, 3-Right.</param> /// <param name="pushForce">Force applied to the entity in the specified direction.</param> /// <param name="stunForce">Stun duration applied to the entity.</param> /// <returns>True if enemy was damaged, otherwise false.</returns> public override bool RecieveAttack(GameObject source, Collider reciever, float damage = 0, int direction = 0, float pushForce = 0, float stunForce = 0) { if (reciever.gameObject == bodyHitbox) { FloatingNumberController fnc = PoolManager.poolManager.GetPoolInstance(floatingNumberPrefab).GetComponent <FloatingNumberController>(); fnc.number = -(int)damage; fnc.textColor = Color.red; fnc.transform.position = transform.position + Vector3.up * .5f + Vector3.right * UnityEngine.Random.Range(-.5f, .5f) + Vector3.forward * UnityEngine.Random.Range(-.5f, .5f); fnc.Init(); Damage(damage, direction, pushForce, stunForce); return(true); } return(false); }
/// <summary> /// The entity takes damage from an unknown source. /// </summary> /// <param name="damage">Ammount of damage to be taken.</param> /// <param name="direction">Incoming damage direction. Axis represented in clockwise order: 0-Forward, 1-Left, 2-Back, 3-Right.</param> /// <param name="pushForce">Force applied to the entity in the specified direction.</param> /// <param name="stunForce">Stun duration applied to the entity.</param> /// <returns>True if enemy was damaged, otherwise false.</returns> public bool Damage(float damage = 0, int direction = 0, float pushForce = 0, float stunForce = 0) { if (isActive && isAlive && !isDespawning) { // Check invencibility if (moveMode != MoveMode.Launched) { // Play sound SoundManager.GetInstance().Play(hurtClip); // Apply damage AddHealth(-damage); // Create floating number effect FloatingNumberController fnc = PoolManager.poolManager.GetPoolInstance(floatingNumberPrefab).GetComponent <FloatingNumberController>(); fnc.number = -(int)damage; fnc.textColor = Color.red; fnc.transform.position = transform.position + Vector3.up * .5f + Vector3.right * UnityEngine.Random.Range(-.1f, .1f) + Vector3.forward * UnityEngine.Random.Range(-.1f, .1f); fnc.Init(); // Apply push if (pushForce > 0) { moveMode = MoveMode.Launched; launchVelocity = Quaternion.AngleAxis(-90 * direction, Vector3.up) * Vector3.forward * pushForce; } // Check for death if (hitpoints <= 0) { PersistanceManager.GetInstance().playerAlive = false; isAlive = false; animator.SetTrigger("Death"); return(true); } } } return(false); }