在使用raycast选择对象并将其移动到播放器左键单击的其他位置时,我需要帮助。到目前为止,我的表现不错,但是我无法选择移动的油缸。这是我到目前为止的代码:
public class ClicknDrag : MonoBehaviour {
private GameObject selected;
private bool unselected = true;
void Update ()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit) && Input.GetMouseButtonDown(0) && hit.transform.tag == "Cylinder" && unselected == true)
{
selected = hit.transform.gameObject;
unselected = false;
}
if (Physics.Raycast(ray,out hit) && unselected == false && Input.GetMouseButtonDown(0))
{
selected.transform.position = hit.transform.position;
unselected = true;
}
}