- Home /
Creating a Line queueing system
Hello all,
I've recently started dabbling with Unity and learning C# at the same time. I am creating a 2D game and at which point right now I am trying to get my Guest AI to go to a ticket booth and form a line until it is their turn to move up.
void Start()
{
List<Vector3> waitingQueuePositionList = new List<Vector3>();
//Creates the start of the line
TicketBoothLineStart = new Vector3 (transform.position.x, transform.position.y - 3);
float positionSize=8f;
//Creates 5 spots in the line
for(int i = 0; i < 5; i++)
{
ticketBoothWaitingQueuePositionList.Add(TicketBoothLineStart + new Vector3(-1,0)*positionSize *i);
}
}
This script is on the ticket booth. It creates a list of vectors that creates the spots in the line.
Now, when my AI wants to go to the ticket booth, I want them to go to the start of the line - "fill" that position in that list and the next AI "fill" the second position and so on. I'm getting quite confused on how to implement this. As this list is a Vector3 list, I am trying to make a second list for the AI so that when they go to the table they get added to the list in a particular order and then can reference the second list in terms of the vector3 positions. I am not sure if this is the approach that it needs to be, but that is what I'm working on right now.
Right now I have a function in my Guest AI script that finds the closest ticket booth, and then grabs that particular ticket booth to get the start of the line and stores it inside ticketBoothStart.
void PurchaseTicket()
{
//Creates array of all objects with tag "tickets"
GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag("Tickets");
//Creates loop to find the closest Ticket Booth
for(int i=0; i < taggedObjects.Length; i++)
{
if(Vector3.Distance(transform.position, taggedObjects[i].transform.position) <= 30)
{
//Once it finds the closest booth, it then goes into the TicketBooth script and grabs the start of the line position
var TicketBoothScript = taggedObjects[i].GetComponent<TicketBooth>();
Vector3 ticketBoothStart = TicketBoothScript.TicketBoothLineStart;
TicketBoothScript.GuestAdd(this.gameObject);
guestLine.Add(this.gameObject); //This is where the error is
ai.destination = ticketBoothStart;
state = State.Idle;
}
}
}
I created a List called List guestLine. I'm trying to make it where once the Guest AI runs this part of the script that it adds themselves to this particular list. When I do that though I am getting a error
Argument 1: cannot convert from 'UnityEngine.GameObject' to 'GuestAI'
I'm doing something wrong obviously or thinking about this the wrong way. Any thoughts would be helpful.
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613023308im_/https://answers.unity.com/themes/thub/images/avi.jpg)