I have three laptops in my scene and I am trying to bring them to front when I click on them. I am able to recognize which laptop is clicked by using the code below, but it doesn't move to the focus position in a single click: it moves only one frame so I have to keep clicking it.
void Update () {
if (Input.GetMouseButtonDown (0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit)) {
if (hit.transform.name == "Laptop 1") {
Debug.Log("Laptop 1 is clicked");
Laptop1Trans.position = Vector3.MoveTowards (Laptop1Trans.position, FocusPointTrans.position, moveSpeed);
} else if (hit.transform.name == "Laptop 2") {
Debug.Log("Laptop 2 is clicked");
} else if (hit.transform.name == "Laptop 3") {
Debug.Log("Laptop 3 is clicked");
} else {
}
}
}
}
I tried moving the move part to a method but still same behaviour.
Are there any workaround?