예제 #1
0
        public void SingleDamageHandlerTest()
        {
            DamageReceiver             receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Damage Receiver");
            MockDamageHandlerBehaviour handler  = receiver.AddComponent <MockDamageHandlerBehaviour>();

            receiver.CallAwakeAndStartRecursive();

            Assert.False(handler.wasDamaged, "Handler damaged before test conditions.");

            receiver.ApplyDamage(1f, Vector3.zero, Vector3.zero, DamageDealer.Default);

            Assert.True(handler.wasDamaged, "Handler not damaged.");
        }
예제 #2
0
        public void TestHealthRemoved()
        {
            DamageReceiver  receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Health Test");
            HealthBehaviour health   = receiver.AddComponent <HealthBehaviour>();

            health.maxHealth = 1f;

            receiver.CallAwakeAndStartRecursive();

            Assert.True(health.IsAlive, "Dead before taking damage");
            Assert.AreEqual(1f, health.CurrentHealth, 0.001f, "Health doesn't match specified value");

            receiver.ApplyDamage(0.75f, Vector3.zero, Vector3.zero, DamageDealer.Default);

            Assert.True(health.IsAlive, "Dead before all health removed");
            Assert.AreEqual(0.25f, health.CurrentHealth, 0.001f, "Health doesn't match specified value minus removed amount");

            receiver.ApplyDamage(0.25f, Vector3.zero, Vector3.zero, DamageDealer.Default);

            Assert.False(health.IsAlive, "Still alive after all health removed");
            Assert.AreEqual(0f, health.CurrentHealth, 0.001f, "Still health remaining after dead");
        }
예제 #3
0
    // Extension method for easily applying damage to the game object owning a component.  Returns true if collider is damageable
    // Ex: bool damageable = collider.ApplyDamage(...);
    public static bool ApplyDamage(this Component component, float amount, Vector3 position, Vector3 force, DamageDealer dealer)
    {
        DamageReceiver receiver = (DamageReceiver)component.GetComponentInParent(typeof(DamageReceiver));

        if (receiver == null)
        {
            return(false);
        }
        else
        {
            receiver.ApplyDamage(amount, position, force, dealer);
            return(true);
        }
    }
예제 #4
0
        public void TestDeathHandler()
        {
            DamageReceiver            receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Health Test");
            HealthBehaviour           health   = receiver.AddComponent <HealthBehaviour>();
            MockDeathHandlerBehaviour handler  = receiver.AddComponent <MockDeathHandlerBehaviour>();

            health.maxHealth = 1f;

            receiver.CallAwakeAndStartRecursive();

            Assert.False(handler.isDead, "Handler dead before taking damage");

            receiver.ApplyDamage(1f, Vector3.zero, Vector3.zero, DamageDealer.Default);

            Assert.True(handler.isDead, "Handler still alive after taking damage");
        }
예제 #5
0
 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         // if the enemy is within the players collider that is tagged "Player" it will switch to the attacking animation and start to damage the player by calling the players ApplyDamage() function.
         if (stayCount > 0.25f)
         {
             animator.SetBool("isAttacking", true);
             attackTarget.ApplyDamage(1);
             // Debug.Log("staying");
             stayCount = stayCount - 0.25f;
         }
         // if the enemy moves outside the player collider then the attacking animation will stop playing
         else
         {
             stayCount = stayCount + Time.deltaTime;
             animator.SetBool("isAttacking", false);
         }
     }
 }