Initial Unity prototype
This commit is contained in:
commit
138750dd52
386 changed files with 40723 additions and 0 deletions
44
Assets/Scripts/PlayerGrabber.cs
Normal file
44
Assets/Scripts/PlayerGrabber.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue