- Home /
What is the best method to queue multiple directions?
Hi everyone
I'm working on something of an endless runner and I found a tutorial on Queues. Following the tutorial I managed to create a row of generated objects that are different.
I am curious what would be the best method of adding more generated rows?
Create a new Queue for every row I wish to have present and updating with the character's movement
There's a way of adding multiple directions/re-positions in one Queue - if there is how can it be achieved?
Currently, the code for one row looks like this:
function Start ()
{
objectQueueTop = new Queue.<Transform>(numberObjectsUp);
for(var x = 0; x < numberObjectsUp; x++)
{
objectQueueTop.Enqueue((Transform).Instantiate(prefab));
}
nextPositionUp = startPositionUp;
for(var y = 0; y < numberObjectsUp; y++)
{
Recycle();
}
}
function Update ()
{
if(objectQueueTop.Peek().localPosition.y + recycleOffset < RunnerScript.distanceTraveledY)
{
Recycle();
}
}
private function Recycle()
{
var positionUp : Vector2 = nextPositionUp;
positionUp.x += 0.5f;
positionUp.y += 0.5f;
var oUp : Transform = objectQueueTop.Dequeue();
oUp.localPosition = positionUp;
objectQueueTop.Enqueue(oUp);
nextPositionUp += gapUp;
}
Any help, tips and pointers will be greatly appreciated.
Thanks!
You need to be a lot more clear. You are using words like "row", "re-positions" and "directions" in an odd way that obfuscates whatever it is you are asking.
Hey $$anonymous$$. Thanks for the comment. To make it more understandable: my character is moving through a row of objects which re-position themselves in front of him. From my experience with queues, currently i'm only able to make them update in one direction (up/down or lateral) and can have only one row/column of objects per queue.
Your answer
Follow this Question
Related Questions
Change transform.position.y in a loop 1 Answer
Queue Order and Billboarded Trees 0 Answers
Re-positioning objects after animation done playing? 1 Answer
Multiple sounds not possible? 0 Answers