How do you use a queuing mechanism in Unity?

How can I use shift + right-click to queue the unit to multiple locations? I wan't to make a game similar to Starcraft. Here's a code that orders the object to move where the right click is pointed.

using UnityEngine; using System.Collections;

public class Marauder : MonoBehaviour {

void Start () {


public float Speed = 0.1f; private Vector3 location; private bool InTransit;

// Update is called once per frame void Update () {

if (Input.GetMouseButtonUp(0))
    Vector3 mousePos = Input.mousePosition;
    Ray ray = Camera.main.ScreenPointToRay(mousePos);

    RaycastHit hitInfo;
    if (Physics.Raycast(
        ray, out hitInfo, Mathf.Infinity))
        location = hitInfo.point;
        InTransit = true;

if (InTransit == true)
    Vector3 Direction = location -

    if (Direction.magnitude > Speed)
        this.transform.position +=
            Direction.normalized * Speed;
        InTransit = false;


Ok, making the next Starcraft killer ;D

You can use a Queue structure...

//Top of script
using System.Collections.Generic;

//To Declare a generic queue
Queue<Vector3> targetQueue = new Queue<Vector3>();

//In Update or similar
if (theUnitHasReachedItsDestination) {

    if (queue.Count > 0) {
        theNewTarget = targetQueue.Dequeue ();
        //The unit should now move towards this point
    } else {
        //All destination points have been reached

//The user has pressed shift and clicked on the point "shiftPoint"
targetQueue.Enqueue (shiftPoint);