Gravity Gun Script -
if (Input.GetButton("Fire2")) // Right click hold: Pull object toward you { if (!isHolding) PullObject(); }
if (isHolding && heldObject != null) { // Move held object to hold point Vector3 targetPos = holdPoint.position; heldObject.velocity = (targetPos - heldObject.position) * pullForce; Gravity gun script
using UnityEngine; public class GravityGun : MonoBehaviour { [Header("References")] public Camera playerCamera; public Transform holdPoint; public LayerMask grabbableLayer; if (Input
heldObject.useGravity = true; heldObject.drag = 1f; heldObject.velocity = playerCamera.transform.forward * throwForce; heldObject = null; isHolding = false; } public Transform holdPoint
void TryGrabObject() { RaycastHit hit; Ray ray = playerCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
