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 -
this.transform.position;
if (Direction.magnitude > Speed)
{
this.transform.position +=
Direction.normalized * Speed;
}
else
{
InTransit = false;
}
}
}