- Home /
how can an AI move by in turn?
Hello guys, I am trying to make a game in an office where customers enter an office take a seat or go to the counter if it's not busy and when the counter is free the waiting customer stands up and goes to the counter, and when he is done he leaves the office then another customer would stand up to go to the counter and so on ... I wrote those scripts that work perfectly
(https://paste.myst.rs/i15r0jz6) AI Customer Attached to each customer prefab (https://paste.myst.rs/kq1zwwmf) Multidimensional list of seats which tells the AI if the seat is busy or is a counter (https://paste.myst.rs/ofus1bdm) Customer Spawner which spawns a random customer in a random given position... The part I am struggling with is that when the counter becomes free how can I make it that it picks a random sitting customer to stand up and go to the counter so I complete that loop of customers coming in and out the store I thought for so long and I couldn't come up with an idea on how I can approach this also if you believe that my code could be written better in any way I would love to know. sorry, the question is too long, Thank you!
Answer by Chubzdoomer · Apr 22 at 10:20 PM
One way you could approach this is to create a CustomerManager
class that contains a list of sitting customers as well as a public function that, when called, 1.) picks a random customer from the "sitting" list, 2.) tells that customer to go to the counter, 3.) removes that customer from the list. The function could be called something like SendSittingCustomerToCounter()
.
The idea is that every customer would have a reference to the CustomerManager
, and the moment one of them left the office he/she would call the manager's public SendSittingCustomerToCounter()
function to let the manager know that another customer was ready to be taken care of.
Another approach would be to set up an event/messaging system, but I think the method I described above is probably the simplest and easiest to get started with.
Your answer
![](https://koobas.hobune.stream/wayback/20220613055708im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[BUG?] Game freezes or I get error. C# 3 Answers
A* Pathfinding Project Point Graphs in 2D 0 Answers
Multiple enemy AI using the same animations/animation controller 1 Answer
AI scripted by player 0 Answers
Unlimited Road car AI 0 Answers