Files
DefendNJ/Assets/_DefendNJ/Scripts/Guns/NewGun/Pistol.cs

90 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Mirror;
using UnityEngine;
public class Pistol : Launcher
{
public override void Start()
{
// 主机自身
if (isServer && isClient && isOwned)
{
type = GunType.Pistol;
AiInfo gunInfo = GameManager.Ins.AiInfos[(int)type];
shootRate = gunInfo.FiringRate;
recoil = 50;
if (hand == HandType.Left)
{
MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger);
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
// 主机其他
else if (isServer && isClient)
{
type = GunType.Pistol;
AiInfo gunInfo = GameManager.Ins.AiInfos[(int)type];
shootRate = gunInfo.FiringRate;
recoil = 50;
}
// 从机自身
else if (isClient && isOwned)
{
if (hand == HandType.Left)
{
MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger);
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
}
public void Update()
{
if (!isOwned)
{
return;
}
// 左手
if (hand == HandType.Left)
{
transform.position = GameLocal.Ins.self.LeftHand.position;
transform.rotation = GameLocal.Ins.self.LeftHand.rotation;
}
// 右手
else if (hand == HandType.Right)
{
transform.position = GameLocal.Ins.self.RightHand.position;
transform.rotation = GameLocal.Ins.self.RightHand.rotation;
}
}
[Client]
public void ClickLeftTrigger()
{
//Debug.Log("点击左trigger");
if(gameObject.activeSelf)
CmdShoot();
}
[Client]
public void ClickRrightTrigger()
{
CmdShoot();
}
[Command]
public void CmdShoot()
{
Shoot();
}
}