public void UpdateState() { Movement player = statePatternEnemy.GetPlayer(); if (player != null) { if (Vector2.Distance(statePatternEnemy.transform.position, statePatternEnemy.player.transform.position) < statePatternEnemy.minObserveDistance) { statePatternEnemy.ChangeState(new ChaseState(statePatternEnemy)); } } }
public void UpdateState() { Movement player = statePatternEnemy.GetPlayer(); if (player != null) { statePatternEnemy.movement.MoveTowardsObject(player); if (Vector2.Distance(statePatternEnemy.transform.position, statePatternEnemy.player.transform.position) < statePatternEnemy.maxAttackDistance && statePatternEnemy.CanSeePlayer() && (Time.time - statePatternEnemy.lastAttackTime > statePatternEnemy.timeBetweenAttacks)) { statePatternEnemy.ChangeState(new AttackState(statePatternEnemy)); } else if ((Time.time - statePatternEnemy.lastAttackTime > 2 * statePatternEnemy.timeBetweenAttacks)) { statePatternEnemy.ChangeState(new AttackState(statePatternEnemy)); } } }