using System; using System.Collections; using System.Collections.Generic; using DragonLi.Core; using DragonLi.Frame; using JetBrains.Annotations; using Mirror; using UnityEngine; public class Shield : Entity, IDamagable { //[NonSerialized] [SyncVar] public float health = 5000f; [NonSerialized] public int Id; public AudioSource audioSource; public AudioClip clip; public Animator animatorS; /// /// 护盾量 /// public float Health { get { return health; } set { health = value; health = Mathf.Clamp(health, 0f, 5000); OnHeathChanged(health); } } public Collider Collider; public bool IsBreak => Health <= 0; [Server] public void ApplyDamage(float value, object info, Transform _sender) { animatorS.SetBool("IsHit", true); CoroutineTaskManager.Instance.WaitSecondTodo(() => { if (animatorS) { animatorS.SetBool("IsHit", false); } }, 0.4f); Debug.Log("护盾受到伤害 - " + value); if (Health - value > 0) { Health -= value; } else { Health = 0; } if (IsBreak) { Break(); } } /// /// When health changed this function will be called /// /// current health public void OnHeathChanged(float currentHealth) { } [Server] public void Break() { Debug.Log("护盾破碎"); Collider.enabled = false; GameManager.Ins.DelShield(Id); NetworkServer.Destroy(gameObject); } }