예제 #1
0
        // private void TriggerAttack()
        // {
        //     anim.ResetTrigger("stopAttack");
        //     anim.SetTrigger("attack");
        // }

        // private void OnCollisionEnter(Collision other) {
        //     print("collision enter: " + other.gameObject.name);
        // }

        private void OnTriggerEnter(Collider other)
        {
            if (this.gameObject.tag.Equals("Player"))
            {
                HandlePlayerHit(other);
            }
            else
            {
                // if(other.gameObject.name=="Player"){
                //     print("target: " + target.gameObject.name);
                //     print("other: " + other.gameObject.name);
                //     print("can trigger: " + currentWeapon.value.GetCanTrigger());
                // }
                if (target == null)
                {
                    return;
                }
                if (!currentWeapon.value.GetCanTrigger())
                {
                    return;
                }
                if (target != other.gameObject.GetComponent <Health>())
                {
                    return;
                }
                if (target.GetInstigatorDamageCooldown(character) > 0)
                {
                    return;
                }
                float  damage = baseStat.GetStat(Stat.Damage);
                Armour armour = other.gameObject.GetComponent <Armour>();

                if (target.IsDamageTaken(character, damage))
                {
                    if (currentWeapon.value != null)
                    {
                        currentWeapon.value.OnHit(armour.GetArmourType());
                    }
                }

                // if (currentWeaponConfig.hasProjectile())
                // {
                //     currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, target, gameObject, damage);
                // }
                // else
                // {
                //     target.TakeDamage(gameObject, damage);
                // }
            }
        }
예제 #2
0
        private void HandlePlayerHit(Collider other)
        {
            bool canTrigger = currentWeapon.value.GetCanTrigger();

            if (!canTrigger)
            {
                return;
            }
            // print("trigger");
            // print(other.gameObject.name);
            Health target = other.gameObject.GetComponent <Health>();
            Armour armour = other.gameObject.GetComponent <Armour>();
            float  damage = GetComponent <BaseStats>().GetStat(Stat.Damage);

            // if(target.IsDamageTaken(GameObject.FindGameObjectWithTag("Player"), damage)){
            //     currentWeapon.value.OnHit(armour.GetArmourType());
            // }
            if ((currentWeapon.value != null && armour != null && target == null) ||
                target.IsDamageTaken(character, damage))
            {
                currentWeapon.value.OnHit(armour.GetArmourType());
            }
            Obstacle obstacle = other.gameObject.GetComponent <Obstacle>();

            if (obstacle != null && obstacle.IsRecoil())
            {
                //trigger obstacle animation
                anim.SetBool("recoiling", true);
                //stop player input in animation?
            }
            if (target == null)
            {
                return;
            }
            // float damage = GameObject.FindGameObjectWithTag("Player").GetComponent<BaseStats>().GetStat(Stat.Damage);
            // if(target.IsDamageTaken(GameObject.FindGameObjectWithTag("Player"), damage)){
            //     currentWeapon.value.OnHit(armour.GetArmourType());
            // }
        }