Пытаясь переместить объект в указанное c положение, я использовал приведенный ниже код, но после отпускания мыши позиция изменилась на другую позицию. Итак, что я пытаюсь сделать, это то, что автопогрузчик подбирает объект и помещает его в указанное c место.
Кто-нибудь знает, где я иду не так, или у вас есть другая идея?
public GameObject item;
public GameObject tempParent;
public Transform guide;
void Start()
{
item.GetComponent<Rigidbody>().useGravity = true;
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown()
{
item.GetComponent<Rigidbody>().useGravity = false;
item.GetComponent<Rigidbody>().isKinematic = true;
item.transform.position = guide.transform.position;
item.transform.rotation = guide.transform.rotation;
item.transform.parent = tempParent.transform;
}
private void OnMouseUp()
{
float horizontalInput = 24.63001f;
float verticalInput = 1.017074f;
item.GetComponent<Rigidbody>().useGravity = false;
item.GetComponent<Rigidbody>().isKinematic = false;
transform.position = new Vector3(horizontalInput, verticalInput, 23.95186f);
}