45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Components;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class TabletManager : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private GameObject tablet;
|
|
[SerializeField] private float spawnDistance = 2f;
|
|
[SerializeField] private float spawnHeight = 1f;
|
|
|
|
[SerializeField] private VRCPickup tabletPickup;
|
|
|
|
private void Start()
|
|
{
|
|
if (!Networking.IsOwner(gameObject))
|
|
{
|
|
Destroy(tabletPickup);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.T) && Networking.IsOwner(gameObject))
|
|
{
|
|
SpawnTablet();
|
|
}
|
|
}
|
|
|
|
private void SpawnTablet()
|
|
{
|
|
// Get local player's position and rotation
|
|
VRCPlayerApi localPlayer = Networking.LocalPlayer;
|
|
if (localPlayer == null || tablet == null) return;
|
|
|
|
Vector3 spawnPos = localPlayer.GetPosition() + (localPlayer.GetRotation() * Vector3.forward) * spawnDistance + Vector3.up * spawnHeight;
|
|
Quaternion spawnRot = localPlayer.GetRotation() * Quaternion.Euler(270, 0, 0);
|
|
|
|
tablet.transform.position = spawnPos;
|
|
tablet.transform.rotation = spawnRot;
|
|
}
|
|
}
|