Files
XMen/Assets/Scripts/Weapons/WeaponProp.cs
2025-07-10 14:49:53 +08:00

81 lines
1.8 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 WeaponType weaponType;
[NonSerialized]
public int amount = 0;
public AudioSource audioSource;
[Server]
public void Init(WeaponType type, int amount)
{
weaponType = type;
this.amount = amount;
ShowWeapon(type);
}
[ClientRpc]
public void ShowWeapon(WeaponType type)
{
Debug.Log("展示武器");
for (int i = 0; i < weapons.Length; i++)
{
weapons[i].SetActive(false);
}
switch (type)
{
case WeaponType.DoubleGun:
weapons[0].SetActive(true);
break;
case WeaponType.LargeGun:
weapons[1].SetActive(true);
break;
case WeaponType.RocketGun:
weapons[2].SetActive(true);
break;
case WeaponType.ShotGun:
weapons[3].SetActive(true);
break;
case WeaponType.GrenadeGun:
weapons[4].SetActive(true);
break;
case WeaponType.SuperGun:
weapons[5].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;
audioSource.Play();
transform.gameObject.SetActive(false);
NetworkServer.Destroy(transform.gameObject);
}
}