Exemplo n.º 1
0
    public override IEnumerator Update()
    {
        /* 공격 가능한 시간이 되면 공격하고.
         * 추격 스테이트로 간다.
         *
         * 공격이 불가능 하다면.
         * 시간을 더하고 추격 스테이트로 간다.
         */

        if (!sc.target.alive)
        {
            sc.Restart();
            yield break;
        }

        controller.modelAnim.Play("idle");

        // 공격 가능한 시간이 되면.
        if (currentTime >= controller.unit.status.attack_speed)
        {
            if (checkTime != null)
            {
                controller.StopCoroutine(checkTime);
                checkTime = null;
            }

            // 공격을 한다.
            AttackStart();

            // 공격이 끝날때 까지 기다린다.
            yield return(new WaitUntil(() => attackAnimComplete));

            // 공격이 끝나면 다시 시간을 계산한다.
            checkTime = sc.StartCoroutine(CheckTime());
        }

        // 스테이지를 변경하고 끝낸다.
        controller.ChangeState(sc.chaseSate);

        yield break;
    }
Exemplo n.º 2
0
    public override IEnumerator Update()
    {
        // 적을 찾는다.
        List <Unit> enemies = FindEnemiesWithTag();

        // 조건. 적이 없다면.
        if (enemies.Count <= 0)
        {
            yield return(new WaitForSeconds(sc.GetRandomDelay()));

            yield break;
        }

        // 가장 가까운 적을 찾는다.
        Unit target = GetClosest(enemies);

        sc.target = target;

        // 조건. 사거리 내에 있는지 확인한다.
        // 사거리 내에 있다면, 상태를 변경한다.
        if (IsInAttackrange(sc.target))
        {
            // 왼쪽이 0
            int dir = (sc.target.transform.position.x - controller.Position.x < 0) ? 0 : 1;
            controller.modelTr.rotation = Quaternion.Euler(new Vector3(0, 180 * dir, 0));

            // 소환 하거나 공격한다.
            if (sc.summonState.IsSummonable())
            {
                sc.ChangeState(sc.summonState);
                yield break;
            }

            else
            {
                sc.ChangeState(sc.attackState);
                yield break;
            }
        }

        // 사거리내에 없다면.
        // 사이에 장애물이 있는지 확인한다.
        if (CheckAround())
        {
            PathRequestManager.RequestPath(new PathRequest(controller.Position, target.transform.position, OnPathFound));
        }

        else
        {
            if (follow != null)
            {
                controller.StopCoroutine(follow);
                follow = null;
            }
            follow = sc.StartCoroutine(this.FollowTarget());
        }
        var range = UnityEngine.Random.Range(0, 100);

        if (range <= 10)
        {
            if (YellowBean.SoundManager.Instance != null)
            {
                if (sc.tag.CompareTo("Yellow") == 0)
                {
                    YellowBean.SoundManager.Instance.PlaySFX(string.Format("y_battle{0}", UnityEngine.Random.Range(0, 7)));
                }
                else
                {
                    YellowBean.SoundManager.Instance.PlaySFX(string.Format("g_battle{0}", UnityEngine.Random.Range(0, 9)));
                }
            }
        }

        yield return(new WaitForSeconds(sc.GetRandomDelay()));

        sc.ChangeState(sc.chaseSate);
    }