void moveNpc() { if (Vector2.Distance(transform.position, targetPosition) < 0.01f) { currentIdleState = NpcIdleState.None; body.velocity = Vector2.zero; return; } Vector2 directionVector = (targetPosition - transform.position).normalized; float xVel = directionVector.x * speed; float yVel = directionVector.y * speed; body.velocity = new Vector2(xVel, yVel); }
void performIdleFunction() { if (currentIdleState == NpcIdleState.Walking) { moveNpc(); } else { time += Time.deltaTime; if (time > actionTimer) { currentIdleState = NpcIdleState.None; } } }
void selectRandomIdleFunction() { currentIdleState = (NpcIdleState)Random.Range(1, 4); if (currentIdleState == NpcIdleState.RandomEvent && (idleEvents == null || idleEvents.Count == 0)) { currentIdleState = NpcIdleState.Walking; } if (currentIdleState == NpcIdleState.Walking) { startMovingToRandomPosition(); } else { if (currentIdleState == NpcIdleState.RandomEvent) { idleEvents[Random.Range(0, idleEvents.Count)].Invoke(); } actionTimer = Random.Range(1f, 3f); time = 0; } }