Unit Production Queue Display
Hello Guys, i'm desperately trying on this and really couldn't find any help for displaying my code, so i'm really hoping one of you guys could help me out. I'm thankful for any advice! I want to make an RTS like game where you can buy different types of units. After you bought them they got added to a queue and get trained - the oldest unit first. So I figured out the basic script for adding a unit with a button and spawn it after some time like so:
public class GUIButtonUnitSpawn : MonoBehaviour
{
public Rect buttonPosition;
public Texture btnTexture;
public GameObject spawnUnit;
public Texture2D unitIcon;
public GameObject spawnObjPos;
public float spawnTime;
private Queue<GameObject> unitQueue = new Queue<GameObject>();
private enum SpawnState { TRAINING, IDLE };
private SpawnState state = SpawnState.IDLE;
private Coroutine trainingCoroutine;
private void OnGUI() {
unitQueue.Enqueue(spawnUnit);
if (trainingCoroutine == null) {
trainingCoroutine = StartCoroutine(TrainingUnit());
}
}
IEnumerator TrainingUnit() {
WaitForSeconds trainingTime = new WaitForSeconds(spawnTime);
state = SpawnState.TRAINING;
while (unitQueue.Count > 0) {
yield return trainingTime;
SpawnUnit(unitQueue.Dequeue());
}
state = SpawnState.IDLE;
trainingCoroutine = null;
}
void SpawnUnit(GameObject spawnUnit) {
Instantiate(spawnUnit, spawnObjPos.transform.position, spawnObjPos.transform.rotation);
}
Next Step is to display the queue and production progress. I have a slider bar which indicates the lasting production time but I really can't wrap my head around how to display the Texture2D icon on the right point in queue when added and move everything to the left if the first unit has finished production and gets deleted from the queue. Are there any ideas how to manage those movements or to translate the position in queue to a transform in my UI etc. ? Thanks in advance!!
Your answer
Follow this Question
Related Questions
Split heavy operation using coroutine 0 Answers
Reset animation in animator when execution the same animation in row 0 Answers
Queue a Coroutine with a List? 1 Answer
How do multiple objects in sequence from a queue? 0 Answers
Texture is bad on device 0 Answers