using UnityEngine; public class PickupThrow : MonoBehaviour { public Transform holdPoint; public float pickupRange = 3f; public float throwForce = 10f; private Rigidbody heldRb; private Transform originalParent; void Update() { // ЛКМ — взяти / відпустити if (Input.GetMouseButtonDown(0)) { if (heldRb == null) TryPickup(); else Drop(false); } // ПКМ — кинути if (Input.GetMouseButtonDown(1) && heldRb != null) Drop(true); } void TryPickup() { if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit, pickupRange)) { if (!hit.collider.CompareTag("Pickable")) return; heldRb = hit.collider.attachedRigidbody; if (heldRb == null) return; originalParent = heldRb.transform.parent; // Вимикаємо фізику heldRb.isKinematic = true; heldRb.useGravity = false; // Прикріплюємо до руки heldRb.transform.SetParent(holdPoint); heldRb.transform.localPosition = Vector3.zero; heldRb.transform.localRotation = Quaternion.identity; } } void Drop(bool throwIt) { // Відкріплюємо heldRb.transform.SetParent(originalParent); // Вмикаємо фізику heldRb.isKinematic = false; heldRb.useGravity = true; if (throwIt) { heldRb.AddForce(Camera.main.transform.forward * throwForce, ForceMode.VelocityChange); } heldRb = null; } }