I have two cubes. One is on the left and the other on the right. I must click on both cubes in order to swap positions via translate. So far I have:
internal var selected : GameObject;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
if (hit.transform.gameObject.tag == "block") {
if (selected) {
if (selected != hit.transform.gameObject) {
hit.transform.Translate(selected.transform.position * Time.deltaTime);
selected.transform.Translate(hit.transform.position * Time.deltaTime);
}
selected = null;
} else {
selected = hit.transform.gameObject;
}
}
}
}
}
That didn’t work out for me. I also wanted to also control the speed of the swap too. Any idea?