40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
public class BombExplosion : Explosion
|
|
{
|
|
public float radius = 3f; // 爆炸半径
|
|
public float damagePerTick = 10f; // 每次伤害
|
|
public override void OnSpawn(TeamType team,float curDurationTime,int id)
|
|
{
|
|
base.OnSpawn(team,curDurationTime,id);
|
|
GunInfo info = GameManager.Ins.GunInfos[(GunType)type][1];
|
|
damagePerTick = info.Damage;
|
|
if (isServer) // 只在服务端计算伤害
|
|
{
|
|
ApplyDamageToPlayers();
|
|
}
|
|
}
|
|
|
|
[Server]
|
|
private void ApplyDamageToPlayers()
|
|
{
|
|
// 假设你有一个所有玩家的列表 GameManager.Ins.AllPlayers
|
|
foreach (var item in NetworkServer.spawned.Values)
|
|
{
|
|
Player player = item.GetComponent<Player>();
|
|
if (player == null) continue;
|
|
|
|
// 计算玩家与回复圈中心的距离
|
|
float dist = Vector3.Distance(transform.position, player.transform.position);
|
|
if (dist <= radius&& player.teamType== curTeam)
|
|
{
|
|
GameManager.Ins.CreateDamageNumber(damagePerTick,player.helmet.position+new Vector3(0,1,0),false);
|
|
player.ApplyDamage(damagePerTick, null, transform);
|
|
}
|
|
}
|
|
}
|
|
}
|