Files
Slendytubbies-VR/Assets/Scripts/Collects/Custard.old
T
2026-10-11 20:26:48 +02:00

71 lines
1.8 KiB
Plaintext

using UnityEngine;
using UnityEngine.Events;
public class Custard : MonoBehaviour
{
public UnityEvent OnCollect;
Rigidbody rb;
MeshCollider collider;
bool wasCollecting = false;
bool smoothing = false;
bool lockSmoothing = false;
bool interactedWith = false;
private void Awake()
{
collider = GetComponent<MeshCollider>();
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (!Player.Instance) return;
if (Vector3.Distance(this.transform.position, Player.Instance.CustardAnchor.position) < 0.5f || lockSmoothing)
smoothing = false;
else
smoothing = true;
if (Player.Instance.collecting && Player.Instance.InRangeForCollectGrab(gameObject))
{
if (!smoothing)
lockSmoothing = true;
wasCollecting = true;
interactedWith = true;
this.transform.position = Vector3.Lerp(this.transform.position, Player.Instance.CustardAnchor.position, (smoothing) ? Time.deltaTime * 10f : 1);
this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Player.Instance.CustardAnchor.rotation, (smoothing) ? Time.deltaTime * 10f : 1);
collider.enabled = false;
rb.isKinematic = true;
} else
{
lockSmoothing = false;
if (wasCollecting)
{
if (Player.Instance.InRangeForCollect(gameObject))
{
if (CollectGamemode.Instance)
CollectGamemode.Instance.CollectCustard(this);
else
Destroy(this.gameObject);
Player.Instance.PlayCollectSound();
if (OnCollect != null)
OnCollect.Invoke();
}
}
wasCollecting = false;
collider.enabled = true;
if (interactedWith)
rb.isKinematic = false;
}
}
}