Files
valheim/Assets/_Valheim/Scripts/Weapons/Weapon.cs
2025-07-04 14:16:14 +08:00

77 lines
1.7 KiB
C#

using System;
using Mirror;
using Valheim;
using UnityEngine.XR;
public class Weapon : NetworkBehaviour
{
[NonSerialized]
[SyncVar]
public HandType hand = HandType.Right;
[NonSerialized]
[SyncVar]
public WeaponType type = WeaponType.Hand;
[NonSerialized]
[SyncVar]
public int playerId = 0;
[NonSerialized]
[SyncVar]
public int atk = 0;
[SyncVar]
public float bullet_amount = 0f;
public void Update()
{
if (!isOwned)
{
return;
}
#if UNITY_EDITOR
// 左手
if (hand == HandType.Left)
{
transform.position = GameInit.Ins.self.LeftHand.position;
transform.rotation = GameInit.Ins.self.LeftHand.rotation;
}
// 右手
if (hand == HandType.Right)
{
transform.position = GameInit.Ins.self.RightHand.position;
transform.rotation = GameInit.Ins.self.RightHand.rotation;
}
#elif !UNITY_EDITOR && UNITY_ANDROID && (PICO || VIVE)
// 左手
if (hand == HandType.Left)
{
transform.position = GameInit.Ins.MRLeftControl.position;
transform.rotation = GameInit.Ins.MRLeftControl.rotation;
}
// 右手
if (hand == HandType.Right)
{
transform.position = GameInit.Ins.MRRightControl.position;
transform.rotation = GameInit.Ins.MRRightControl.rotation;
}
#endif
}
public void StuffBullet(int amount)
{
bullet_amount += amount;
}
public virtual void UserWeapon( bool isDown)
{
bullet_amount -= 1;
}
public virtual void ResetWeapon() { }
}