I’m making a FPS on rails. The camera is locked in a single position so the player can’t look around, but can move their cursor around the screen. I have a script for moving the crosshair around the screen. I just can’t figure out how I could expand this to instantiate objects (shoot) from the crosshair. Any help is greatly appreciated.
private var screenPoint : Vector3;
private var offset : Vector3;
function Update() {
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint (new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
function OnMouseDrag() {
var curScreenPoint : Vector3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
var curPosition : Vector3 = Camera.main.ScreenToWorldPoint (curScreenPoint) + offset;
transform.position = curPosition;
}