Files
Zombie/Assets/_Zombie/Scripts/Guns/WeaponProp.cs
2025-08-28 10:44:46 +08:00

71 lines
1.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using JetBrains.Annotations;
using Mirror;
using UnityEngine;
using UnityEngine.PlayerLoop;
public class WeaponProp : NetworkBehaviour
{
public Collider box;
public GameObject[] weapons;
[NonSerialized]
public GunType weaponType;
[NonSerialized]
public int amount = 0;
[Server]
public void Init(GunType type, int amount)
{
weaponType = type;
this.amount = amount;
ShowWeapon(type);
}
public void ShowWeapon(GunType type)
{
Debug.Log("展示武器");
for (int i = 0; i < weapons.Length; i++)
{
weapons[i].SetActive(false);
}
switch (type)
{
case GunType.FireGun:
weapons[0].SetActive(true);
break;
case GunType.LaserGun:
weapons[1].SetActive(true);
break;
case GunType.LightSphereGun:
weapons[2].SetActive(true);
break;
case GunType.BeamGun:
weapons[3].SetActive(true);
break;
case GunType.GrenadeGun:
weapons[4].SetActive(true);
break;
}
}
public void Start()
{
if (isServer)
{
transform.DORotate(new Vector3(0f, 360f, 0f), 5f, RotateMode.LocalAxisAdd).SetLoops(-1, LoopType.Restart);
}
}
[Server]
public void Collider()
{
box.enabled = false;
transform.gameObject.SetActive(false);
NetworkServer.Destroy(transform.gameObject);
}
}