Hi guys,
Been working on this one most of the day. It seems relatively simple but it's been giving me a real headache.
Picking up and dropping objects is pretty easy, just use the OnMouseDown + OnMouseDrag. My problem occurs because I want to use the right mouse button, and Unity only has these special functions for the left button.
Here's the code I've got so far. It works, except to pick up the object you need to right-click on it, then left-click and drag to execute the OnMouseDrag function.
var screenSpace;
var offset;
function Update() {
if(Input.GetMouseButton(1)) {
gameObject.GetComponent(Rigidbody).freezeRotation = true;
screenSpace = Camera.main.WorldToScreenPoint(transform.position);
offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
}
else {
gameObject.GetComponent(Rigidbody).freezeRotation = false;
}
}
function OnMouseDrag() {
//if(Input.GetMouseButton(1)) {
var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
transform.position = curPosition;
//}
}
How exactly would I go about replacing the OnMouseDrag to that it can be executed with the right mouse button only?