private void Update() { if (enemy.currentState == EnemyState.Dead) { return; } if (enemy.seePlayer) { if (!sawPlayer) { sawPlayer = true; wasAtSpawn = false; } if (enemy.CheckAttackDistance()) { move.StopMoving(); enemy.Attack(); } else { if (enemy.currentState != EnemyState.Attack && enemy.currentState != EnemyState.Hurt) { enemy.currentState = EnemyState.Chasing; move.Move(enemy.GetDirectionToPlayer()); } } } else { if (sawPlayer) { StartCoroutine(CalmDownCo()); } var checkedDistanceToSpawn = move.CheckDistanceToTarget(spawnPoint, 1f); if (!checkedDistanceToSpawn && !sawPlayer && !wasAtSpawn) { enemy.currentState = EnemyState.Patrolling; move.Move(move.GetDirectionToTarget(spawnPoint, true) * 0.5f); } else if (checkedDistanceToSpawn && !sawPlayer && !wasAtSpawn) { wasAtSpawn = true; } else if (!sawPlayer && wasAtSpawn) { Patrolling(); } else { enemy.currentState = EnemyState.Idle; move.StopMoving(); } } }
protected override void Update() { base.Update(); if (isOpened && !move.CheckDistanceToTarget(openPosition.position, 0.1f)) { move.Move(move.GetDirectionToTarget(openPosition.position, false)); DisableInteract(); } else if (!isOpened && !move.CheckDistanceToTarget(closedPosition.position, 0.1f)) { move.Move(move.GetDirectionToTarget(closedPosition.position, false)); DisableInteract(); } else { move.StopMoving(); EnableInteract(); } }
public bool CheckDistanceToPlayer(float distance) { var playerPosition = player.transform.position; return(move.CheckDistanceToTarget(playerPosition, distance) && player.health.CheckDead()); }