RTS Unit Creation Bar Queue System

Hi, I’m creating an RTS game where you can build troops from a dropdown menu, I’ve set up little bars that show the progress of the current troop being made. I have one problem that I’m not sure how to fix, how can I make only one bar work at a time based off what I clicked? Right now if I click on any of them they start building like they are suppose too but I only want one troop to be built at a time then after its built it moves on to the next thing that was clicked after it started being built. I hope this question isn’t too confusing ask questions If you don’t know what I’m talking about and Ill get back to you otherwise thanks for reading!! Any help will be appreciated!

I had built a similar system, but for an unrelated process.

You can make a class file…along the lines of:

class TroopBuilderJob //Can go in its own script, or the bottom of another script.
{
public TroopType ToBeBuilt = Whatever; //Make a public Enum including your troop types.
public int AmountToBeBuilt = 0; //The amount of the troop type to be built.
}

Then, on your actual “builder” script,

Utilize a Queue:

public static Queue<TroopBuilderJob> TroopBuilderQueue = new Queue<TroopBuilderJob>(); //This will hold your build queue. You'll want to loop through this and pull info from it.

Do something along the lines of:

    bool UseExisting = false; //Use existing TroopBuilderJob?
    foreach(TroopBuilderJob i in MasterBuilderScript.TroopBuilderQueue)
    {
    if (i.ToBeBuilt == Infantry) {
//If an existing TroopBuilderJob exists, we'll use it instead of making a new one.
    i.AmountToBeBuilt++; //Adding the amount by 1.
    UseExisting = true; //Sets the "UseExisting" to true.
    }
    }
    
    if (!UseExisting)
    {
//Since no previous build job matches the troop type we're attempting to make..we're going to make a new one.
    TroopBuilderJob tb = new TroopBuilderJob();
    tb.ToBeBuilt = Infantry; //Set this to the type of unit you're building.
    tb.AmountToBeBuilt = 1; //I assume you're going to increment by 1.
    MasterBuilderScript.TroopBuilderQueue.Add(tb); //Adds the newly created TroopBuilderJob to the master list...which you will parse through.
    }

That’ll basically search for an existing class, if it’s in the queue.

You can modify it if you’d like, but i’d recommend deleting the TroopBuilderJob from the Queue once the AmountToBeBuilt is 0.