Initial Unity prototype

This commit is contained in:
apolloxyx 2025-05-07 23:02:10 -04:00
commit 138750dd52
386 changed files with 40723 additions and 0 deletions

View file

@ -0,0 +1,44 @@
using UnityEngine;
public class PlayerGrabber : MonoBehaviour
{
public float grabDistance = 2f;
private CartGrabAndHold heldCart;
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
if (heldCart == null)
{
TryGrabCart();
}
else
{
heldCart.ReleaseCart();
heldCart = null;
}
}
if (heldCart != null)
{
heldCart.HoldCart(); // Let it keep following while held
}
}
void TryGrabCart()
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, grabDistance))
{
CartGrabAndHold cart = hit.collider.GetComponent<CartGrabAndHold>();
if (cart != null)
{
heldCart = cart;
cart.GrabCart(transform);
}
}
}
}