SingleHandedChef/Assets/Scripts/Pickable.cs
2023-08-20 14:59:02 +05:30

48 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickable : MonoBehaviour
{
public Rigidbody rb;
public Transform handlingPoint;
public bool isGrabbing;
void OnValidate(){
if(handlingPoint == null){
handlingPoint = transform;
}
if(rb == null){
rb = GetComponent<Rigidbody>();
}
}
void Start()
{
ogParent = transform.parent;
}
// Update is called once per frame
void Update()
{
}
Transform ogParent;
public void Grab(){
rb.isKinematic=true;
isGrabbing=true;
transform.localRotation = new Quaternion(0,0,0,0);
transform.parent = ItemGrabber.instance.holdingPoint;
transform.localPosition = transform.position - handlingPoint.position;
}
public void LetGo(Vector3 vel){
isGrabbing = false;
transform.parent = ogParent;
rb.isKinematic=false;
rb.AddForce(vel * 100, ForceMode.VelocityChange);
}
}