예제 #1
0
        protected override void Hit(Unit hitUnit, Collider other)
        {
            base.Hit(hitUnit, other);

            // 히트지점으로부터 range내의 모든 유닛들을 가져온다.
            var units = KUtils.GetOverlapUnitsNonAlloc(this.transform.position, this.range);

            KUtils.DebugDrawSphere(this.transform.position, this.range); // 디버깅할때 범위 확인용!

            for (int i = 0; i < units.Count; i++)
            {
                //유닛끼리 서로 다른 진영일경우, 대미지를 준다
                if (units[i].unitSide != this.owner.unitSide)
                {
                    units[i].DealDamage(this.owner, Mathf.RoundToInt(Calculator.RandomDamage(damage)));
                }
            }

            Finish();
        }
예제 #2
0
        /// <summary>
        /// 특정위치에 범위공격을 가한다.
        /// mySide : 공격하는 사람의 진영. 반대 side의 유닛에게 대미지를 준다.
        /// </summary>
        public static void SimpleRangeDamage(Unit attackedUnit, Vector3 position, float radius, UnitSide mySide, float damage, string hitEffectPath, string hitSoundPath)
        {
            var units = KUtils.GetOverlapUnitsNonAlloc(position, radius);

            KUtils.DebugDrawSphere(position, radius);

            for (int i = 0; i < units.Count; i++)
            {
                //자기 자신이면 무시한다.
                if (units[i] == attackedUnit)
                {
                    continue;
                }

                //유닛끼리 서로 다른 진영일경우, 대미지를 준다
                if (units[i].unitSide != mySide)
                {
                    units[i].DealDamage(attackedUnit, Mathf.RoundToInt(Calculator.RandomDamage(damage)));


                    ///////////////////////////////////////////
                    // 이펙트 처리
                    bool useHitEffect = !string.IsNullOrEmpty(hitEffectPath);
                    bool useHitSound  = !string.IsNullOrEmpty(hitSoundPath);

                    // 이펙트를 재생해야 한다면
                    if (useHitEffect || useHitSound)
                    {
                        Vector3 targetPoint; // 히트지점을 계산해야됨.

                        // 발화점과, 히트 유닛간의 레이를 쏜다.
                        Ray        ray = new Ray(position, units[i].transform.position - position);
                        RaycastHit hit;

                        Debug.DrawRay(ray.origin, ray.direction, Color.red, 3);
                        if (Physics.Raycast(ray, out hit, radius, Layers.Unit, QueryTriggerInteraction.Collide))
                        {
                            // 레이로 검출이 된다면 검출된 지점에 히트이펙트
                            targetPoint = hit.point;
                        }
                        else
                        {
                            // 레이로 검출이 되지 않는다면 맞은 유닛에 그냥 표시
                            targetPoint = units[i].pivots.center.position;
                        }


                        // 이펙트가 필요하면 생성
                        if (useHitEffect)
                        {
                            ParticleSystem ps = ObjectPoolManager.inst.Get <ParticleSystem>(hitEffectPath);
                            ps.transform.position      = targetPoint;
                            ps.transform.localRotation = Quaternion.identity;
                            ps.transform.localScale    = Vector3.one;
                            ps.Play();
                        }

                        // 사운드가 필요하면 재생
                        if (useHitSound)
                        {
                            SoundManager.inst.PlaySound(hitSoundPath, targetPoint);
                        }
                    }
                }
            }
        }