108 lines
2.2 KiB
C#
108 lines
2.2 KiB
C#
using DarkTonic.MasterAudio;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
public class GatlingTower : ManualTower
|
|
{
|
|
public Transform launcher;
|
|
public Launcher[] guns;
|
|
|
|
[SoundGroup] public string motorSound;
|
|
|
|
private int _angleZ = 0;
|
|
private float _nextShootTime = 0;
|
|
private int _gunIndex = 0;
|
|
|
|
[SyncVar]
|
|
public bool cacheShooting = false;
|
|
|
|
public override void OnSpawn(int id, TowerType type, int lvl)
|
|
{
|
|
base.OnSpawn(id, type, lvl);
|
|
_nextShootTime = Time.time + gcd;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
if (!isServer)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!IsAlive || state == TowerState.Broken)
|
|
{
|
|
return;
|
|
}
|
|
|
|
bool isShooting = false;
|
|
// 手动模式
|
|
if ((mode == TowerMode.Manual || mode == TowerMode.Joint) && controllerId != -1)
|
|
{
|
|
isShooting = true;
|
|
_angleZ += 8;
|
|
if (_angleZ >= 360)
|
|
{
|
|
_angleZ = 0;
|
|
}
|
|
|
|
launcher.localEulerAngles = new Vector3(0, 0, _angleZ);
|
|
|
|
if (Time.time < _nextShootTime)
|
|
{
|
|
return;
|
|
}
|
|
|
|
guns[_gunIndex].Shoot(controllerId);
|
|
_nextShootTime = Time.time + gcd;
|
|
_gunIndex++;
|
|
// 重置
|
|
if (_gunIndex % guns.Length == 0)
|
|
{
|
|
_gunIndex = 0;
|
|
}
|
|
}
|
|
|
|
if (cacheShooting != isShooting)
|
|
{
|
|
// 开始自转
|
|
if (isShooting)
|
|
{
|
|
PlayMotorSound();
|
|
}
|
|
// 停止自转
|
|
else
|
|
{
|
|
StopMotorSound();
|
|
}
|
|
|
|
cacheShooting = isShooting;
|
|
}
|
|
}
|
|
|
|
// [Server]
|
|
// public override void EnterTower()
|
|
// {
|
|
// base.EnterTower();
|
|
// }
|
|
|
|
// [Server]
|
|
// public override void ExitTower()
|
|
// {
|
|
// base.ExitTower();
|
|
// }
|
|
|
|
[ClientRpc]
|
|
public void PlayMotorSound()
|
|
{
|
|
MasterAudio.PlaySound3DAtTransform(motorSound, head);
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void StopMotorSound()
|
|
{
|
|
MasterAudio.StopSoundGroupOfTransform(head, motorSound);
|
|
}
|
|
}
|