public IEnumerator EnemyAttack() { while (currentState == EMENY_STATE.ATTACK) { Debug.Log("Attacking!"); agent.isStopped = false; agent.SetDestination(playerTransform.position); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance > agent.stoppingDistance) { CurrentState = EMENY_STATE.CHASE; yield break; } else { playerHealth.HealthPoints -= maxDemage * Time.deltaTime; } yield return(null); } yield break; }
public IEnumerator EnemyChase() { while (currentState == EMENY_STATE.CHASE) { checkVision.Sensitity = CheckVision.enmSensitity.LOW; agent.isStopped = false; agent.SetDestination(checkVision.lastKnownSighting); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance <= agent.stoppingDistance) { agent.isStopped = true; if (!checkVision.targetInSight) { CurrentState = EMENY_STATE.PATROL; } else { CurrentState = EMENY_STATE.ATTACK; } yield break; } yield return(null); } }
// Start is called before the first frame update void Start() { /*GameObject[] destinations = GameObject.FindGameObjectsWithTag("Dest"); * patrolDestination = destinations[Random.Range(0, destinations.Length)] * .GetComponent<Transform>(); * * CurrentState = EMENY_STATE.PATROL; */ GameObject[] destinations = GameObject.FindGameObjectsWithTag("Dest"); int pathIndex = Random.Range(0, destinations.Length); patrolDestination = destinations[Random.Range(0, destinations.Length)].GetComponent <Transform>(); // print($"Path: {pathIndex}"); CurrentState = EMENY_STATE.PATROL; }
public IEnumerator EnemyPatrol() { while (currentState == EMENY_STATE.PATROL) { checkVision.Sensitity = CheckVision.enmSensitity.HIGH; agent.isStopped = false; agent.SetDestination(patrolDestination.position); while (agent.pathPending) { yield return(null); } if (checkVision.targetInSight) { agent.isStopped = true; CurrentState = EMENY_STATE.CHASE; yield break; } yield return(null); } }