Files
Slendytubbies-VR/Assets/Scripts/Player/Player.cs
T
2026-10-11 20:26:48 +02:00

102 lines
2.3 KiB
C#

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.XR.Interaction.Toolkit.Locomotion.Movement;
public class Player : MonoBehaviour
{
public static Player Instance;
public HeldInteractions HeldInteractions;
public Camera Camera;
[Header("Components")]
public Spookys spookys;
[Header("Toggles")]
public bool SpookyImages = true;
[Header("Collect Interaction")]
public AudioSource CollectSound;
public Transform CollectInteractor;
public Transform CollectLocation;
public float CollectGrabRange = 4;
public float CollectRange = 2;
[Header("Anchors")]
public Transform CustardAnchor;
[Header("Speeds")]
public float WalkSpeed = 5;
public float RunSpeed = 7.05f;
[Header("Movement")]
public ContinuousMoveProvider MoveProvider;
[Header("Input")]
public InputActionProperty CollectAction;
public InputActionProperty RunAction;
[HideInInspector] public Transform Collecting;
[HideInInspector] public bool running = false;
[HideInInspector] public bool collecting = false;
private void Awake()
{
Instance = this;
}
private void Start()
{
spookys.enabled = SpookyImages;
}
private void Update()
{
running = RunAction.action.ReadValue<float>() > 0.9f;
collecting = CollectAction.action.ReadValue<float>() > 0.5f && HeldInteractions.OffHandFree;
MoveProvider.moveSpeed = (running) ? RunSpeed : WalkSpeed;
}
public bool InRangeForCollectGrab(GameObject who)
{
return Vector3.Distance(who.transform.position, CollectInteractor.position) < CollectGrabRange;
}
public bool InRangeForCollect(GameObject who)
{
return Vector3.Distance(who.transform.position, CollectLocation.position) < CollectRange;
}
public void PlayCollectSound()
{
CollectSound.Stop();
CollectSound.pitch = Random.Range(0.9f, 1.1f);
CollectSound.Play();
}
private void OnDrawGizmos()
{
if (CollectInteractor)
{
Gizmos.color = Color.pink;
Gizmos.DrawLine(CollectInteractor.position, CollectInteractor.position + CollectInteractor.forward * CollectGrabRange);
Gizmos.color = Color.white;
}
if (CollectLocation)
{
Gizmos.color = Color.purple;
Gizmos.DrawWireSphere(CollectLocation.position, CollectRange);
Gizmos.color = Color.white;
}
}
public void Kill()
{
SceneManager.LoadScene("Dead");
}
}