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

96 lines
1.8 KiB
C#

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;
/// <summary>
/// 护盾量
/// </summary>
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();
}
}
/// <summary>
/// When health changed this function will be called
/// </summary>
/// <param name="currentHealth">current health</param>
public void OnHeathChanged(float currentHealth)
{
}
[Server]
public void Break()
{
Debug.Log("护盾破碎");
Collider.enabled = false;
GameManager.Ins.DelShield(Id);
NetworkServer.Destroy(gameObject);
}
}