I’ve just started with Unity 3D and C# and can understand most code due to my expirience with Objective C and AS3.
I’m following a tutorial however ( RTS Tutorial - Part 10 ) and it’s not working as it should.
The goal is to add a unit to a building queue and after some seconds the unit is created.
View buildingqueue each frame
protected override void Update () {
base.Update ();
ProcessBuildQueue ();
}
Code called when the icon of the unit is clicked, the log shows me that there is 1 element in the queue
protected void CreateUnit(string unitName){
buildQueue.Enqueue (unitName);
Debug.Log ("CreateUnit " + buildQueue.Count);
}
This is where it gets weird, this Log tells me there are 0 elements in my queue. So where did that 1 element go in the 1 frame delay there is between these 2 methods ?
protected void ProcessBuildQueue(){
Debug.Log("ProcessBuildQueue "+buildQueue.Count);
if (buildQueue.Count > 0) {
currentBuildProgress += Time.deltaTime * ResourceManager.buildSpeed;
if(currentBuildProgress > maxBuildProgress){
if(player) player.addUnit(buildQueue.Dequeue(), spawnPoint, transform.rotation);
currentBuildProgress = 0.0f;
}
}
}
There’s a very good chance that I’m missing something small, maybe not even in the code ?
Anyway, any help would be fantastic.