Exemplo n.º 1
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);
    }