Hopefully it's obvious what the problem is in the code. Can't quite figure out how to get around it. The object rotates how I want but only a incrementally because the loop then waits for (Input.GetMouseButtonDown(1) again on the next frame which stops the rotation. Any ideas?
void Update () {
if (Input.GetMouseButtonDown(1)){
GameObject[] sl;
sl = GameObject.FindGameObjectsWithTag("White");
foreach(GameObject slt in sl) {
UnitStats us = (UnitStats)slt.GetComponent("UnitStats");
if (us.selected == true && us.movementphase == 0) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.transform.tag == "Ground"){
moveTo = hit.point;
UnitSelect rs = (UnitSelect)GetComponent("UnitSelect");
moveFrom = rs.selectedTarget.transform;
Debug.Log(moveTo);
moveTo.y = moveFrom.position.y;
moveFrom.rotation = Quaternion.Slerp(moveFrom.rotation, Quaternion.LookRotation(moveTo - moveFrom.position), rotationSpeed * Time.deltaTime);
}
}
}
}
}
↧