Esempio n. 1
0
    void OnTriggerEnter(Collider collision)
    {
        enemyHealth = collision.gameObject.GetComponent <EnemyHealth> ();

        switch (attackType)
        {
        case AttackType.AOEAttack:
            Debug.Log("AOE Attack!");
            if (collision.gameObject.tag == "Enemy")
            {
                Rigidbody enemy = collision.gameObject.GetComponentInChildren <Rigidbody> ();
                Vector3   force = enemy.position - weaponCollider.transform.position;
                force.Normalize();
                force *= AOEPower;
                enemy.AddForce(force, ForceMode.Impulse);
                enemyHealth.TakeDamage(5);

                //SFX
                soundManager.spinHitSound();
            }
            break;

        case AttackType.meleeAttack:
            Debug.Log("PUNCH!");
            if (collision.gameObject.tag == "Enemy")
            {
                Rigidbody enemy = collision.gameObject.GetComponentInChildren <Rigidbody> ();
                Vector3   force = attackVector;
                force.Normalize();
                force *= meleePower;
                enemy.AddForce(force, ForceMode.Impulse);
                enemyHealth.TakeDamage(10);

                //SFX
                soundManager.punchHitSound();
            }
            break;
        }
    }