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 // 투석기만 좌우가 다르다. // 왼쪽이 1 int dir = (sc.target.transform.position.x - controller.Position.x < 0) ? 1 : 0; controller.modelTr.rotation = Quaternion.Euler(new Vector3(0, 180 * dir, 0)); 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()); } yield return(new WaitForSeconds(sc.GetRandomDelay())); sc.ChangeState(sc.chaseSate); }
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; } currentTime = 0f; // 공격을 한다. AttackStart(); // 공격이 끝날때 까지 기다린다. yield return(new WaitUntil(() => attackAnimComplete)); // 공격이 끝나면 다시 시간을 계산한다. checkTime = sc.StartCoroutine(CheckTime()); } // 스테이지를 변경하고 끝낸다. controller.ChangeState(sc.chaseSate); yield break; }