using System; using System.Collections; using System.Collections.Generic; using DamageNumbersPro; using DarkTonic.MasterAudio; using DragonLi.Core; using DragonLi.Frame; using Mirror; using UnityEngine; public class DamageBox : MonoBehaviour, IDamagable { public ShieldExplosion ex; public float Health { get; set; } public TeamType team; public bool isDie; public Collider collider; [SoundGroup] public string audioSound; private bool _isServer; public int id; private void Start() { isDie = false; } public void Init(int curId,TeamType curTeam,float hp,bool isServer) { id=curId; team = curTeam; Health = hp; _isServer=isServer; if(collider==null) collider = gameObject.AddComponent(); collider.enabled = true; SetTeamLayer(); } public void ApplyDamage(float value, int info, Transform _sender,int score) { if(isDie) return; if (_isServer) { GameManager.Ins.RpcShowDamageNumber(value,_sender.position,false); } Health -= value; if (Health <= 0&& !isDie) { isDie = true; collider.enabled = false; ex.HideModel(id); } } void SetTeamLayer() { // 根据队伍设置层 if (team == TeamType.Red) { gameObject.layer = LayerMask.NameToLayer("Shield_Red"); } else { gameObject.layer = LayerMask.NameToLayer("Shield_Blue"); } // 根据层级动态屏蔽碰撞(只屏蔽友方子弹) // int layerShield = gameObject.layer; // int layerBulletRed = LayerMask.NameToLayer("Bullet_Red"); // int layerBulletBlue = LayerMask.NameToLayer("Bullet_Blue"); // // // Red Shield 屏蔽 Red Bullet // Physics.IgnoreLayerCollision( // LayerMask.NameToLayer("Shield_Red"), // layerBulletRed, // true // ); // // // Blue Shield 屏蔽 Blue Bullet // Physics.IgnoreLayerCollision( // LayerMask.NameToLayer("Shield_Blue"), // layerBulletBlue, // true // ); } }