/// <summary>
        /// 총알을 발사하고
        /// 설정한다.
        /// </summary>
        void FireBullet()
        {
            EnemyBullet bullet = GameObject.Instantiate <EnemyBullet>();

            Vec2D bulletPoint = gameObject.transform.position;

            bulletPoint.Y            += 8;
            bullet.transform.position = bulletPoint;

            DamageSystem damageSystem = bullet.GetComponent <DamageSystem>();

            damageSystem.EventGiveDamage += () => GameObject.Destroy(bullet);
        }
예제 #2
0
        /// <summary>
        /// 총알을 생성하고 좌표를 위로 조금 올려준다.
        /// </summary>
        void FireBullet()
        {
            PlayerBullet bullet = GameObject.Instantiate <PlayerBullet>();

            Vec2D bulletPoint = gameObject.transform.position;

            bulletPoint.Y            -= 8;
            bullet.transform.position = bulletPoint;

            DamageSystem damageSystem = bullet.GetComponent <DamageSystem>();

            damageSystem.EventGiveDamage += () => GameObject.Destroy(bullet);

            GameManager.Instance.IncreaseFireCount(1);
        }
        /// <summary>
        /// slot에 설정된 적 유닛의 로직을 설정한다.
        /// 각 컴포넌트에 이벤트를 추가한다.
        /// </summary>
        /// <param name="slot">설정할 슬롯</param>
        /// <param name="score">죽으면 추가할 점수</param>
        private void SetupEnemy(Slot slot, int score)
        {
            BezierCurveMove move         = slot.gameObject.GetComponent <BezierCurveMove>();
            HealthSystem    health       = slot.gameObject.GetComponent <HealthSystem>();
            DamageSystem    damageSystem = slot.gameObject.GetComponent <DamageSystem>();

            //damageSystem.EventGiveDamage += () => health.GetDamage(2);

            // 한번만 작동하게 하는 이벤트 삽입
            // 자기 자신에게 데미지 주기
            Action selfDamage = null;

            selfDamage = () =>
            {
                damageSystem.EventGiveDamage -= selfDamage;
                health.GetDamage(2);
            };
            damageSystem.EventGiveDamage += selfDamage;

            // 죽으면 애니메이션 재생하게 하기
            health.EventOnDead += () =>
            {
                slot.gameObject.collider.Enabled = false;
                move.Enabled = false;
                AnimationSprite animation = slot.gameObject.GetComponent <AnimationSprite>();
                animation.ImageCurrentIndex   = 0;
                animation.ImageChangeInterval = 0.1f;
                animation.ImageList.Clear();
                animation.ImageList.Add(Resources.enemy_die_01);
                animation.ImageList.Add(Resources.enemy_die_02);
                animation.ImageList.Add(Resources.enemy_die_03);
                animation.ImageList.Add(Resources.enemy_die_04);
                animation.ImageList.Add(Resources.enemy_die_05);
                // 재생 다하면 오브젝트 삭제
                animation.EventPrintedAllImage += () => GameObject.Destroy(slot.gameObject, 0);
                animation.EventPrintedAllImage += () => slot.gameObject = null;
            };
            // 점수 증가
            health.EventOnDead += () => GameManager.Instance.IncreaseScore(score);
            health.EventOnDead += () => aliveUnits.Remove(slot.gameObject);

            // 보스몬스터일경우 남은 HP가 1이면 애니메이션 스프라이트 변경
            if (slot.gameObject as Enemy03 != null)
            {
                health.EventGetDamage += (leftHP) =>
                {
                    if (leftHP == 1)
                    {
                        AnimationSprite animationSprite = slot.gameObject.GetComponent <AnimationSprite>();
                        if (animationSprite != null)
                        {
                            animationSprite.ImageList.Clear();
                            animationSprite.ImageList.Add(Resources.Enemy_03_03_01);
                            animationSprite.ImageList.Add(Resources.Enemy_03_03_01);
                        }
                    }
                    else if (leftHP == 2)
                    {
                        AnimationSprite animationSprite = slot.gameObject.GetComponent <AnimationSprite>();
                        if (animationSprite != null)
                        {
                            animationSprite.ImageList.Clear();
                            animationSprite.ImageList.Add(Resources.Enemy_03_02_01);
                            animationSprite.ImageList.Add(Resources.Enemy_03_02_01);
                        }
                    }
                };
            }
        }