Added many other
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public sealed class PlayerHandController : NetworkBehaviour, IPlayerSystem
|
||||
{
|
||||
[SerializeField] private Transform itemSocket;
|
||||
|
||||
private bool isInitialized;
|
||||
|
||||
public Transform ItemSocket => itemSocket;
|
||||
|
||||
public void Initialize(PlayerFacade facade)
|
||||
{
|
||||
if (itemSocket == null)
|
||||
{
|
||||
Transform candidate = transform.Find("HandItemSocket");
|
||||
if (candidate != null)
|
||||
itemSocket = candidate;
|
||||
}
|
||||
|
||||
isInitialized = itemSocket != null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isInitialized || !IsOwner || Keyboard.current == null)
|
||||
return;
|
||||
|
||||
if (!NetworkHandItemInteractable.TryGetHeldItem(
|
||||
OwnerClientId,
|
||||
out NetworkHandItemInteractable heldItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
|
||||
heldItem.RequestUse();
|
||||
|
||||
if (Keyboard.current.gKey.wasPressedThisFrame)
|
||||
heldItem.RequestThrow();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!IsOwner ||
|
||||
!NetworkHandItemInteractable.TryGetHeldItem(
|
||||
OwnerClientId,
|
||||
out NetworkHandItemInteractable heldItem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GUIStyle style = new(GUI.skin.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontSize = 15,
|
||||
normal = { textColor = Color.white }
|
||||
};
|
||||
|
||||
Rect area = new(0f, Screen.height * 0.68f, Screen.width, 28f);
|
||||
GUI.Label(area, $"{heldItem.ItemName} [LMB] Use [G] Throw", style);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50c1c3213ec617f4fb43a65d112b4736
|
||||
Reference in New Issue
Block a user