// Update is called once per frame void Update() { switch (status) { case Status.Find: float takeActionValue; takeActionValue = Random.Range(0.0f, 1.0f); if (takeActionValue <= takeCloseCoverRate) { status = Status.Hide; } else { takeActionValue = Random.Range(0.0f, 1.0f); } if (takeActionValue <= directAttackRate) { status = Status.Shoot; } break; case Status.Hide: CoverPoint closeistPoint = coverPoints[0]; foreach (var point in coverPoints) { if ((point.position - player.transform.position).magnitude < closeistPoint.GetMagnitudeWith(player.transform.position)) { closeistPoint = point; } } Vector3 pos = closeistPoint.position; float zOffset = player.transform.position.z > agentObject.transform.position.z ? -coverZDistence : coverZDistence; agent.destination = new Vector3(pos.x, pos.y, pos.z + zOffset); if (agent.remainingDistance < distanceFromCoverPoint) { curGunfireCount = minGunFireCount; status = Status.Shoot; } break; case Status.Shoot: curFireDelay += Time.deltaTime; agent.destination = player.transform.position; if (curFireDelay >= fireDelay) { objPool.CreateBullet(1, agent.transform.position, (player.transform.position - agent.transform.position).normalized, "EnemyBullet"); Debug.Log("Fire!!"); curGunfireCount--; curFireDelay = 0; } if (curGunfireCount <= 0) { status = Status.Find; } break; } SyncSpriteToAgent(); }