您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

43 行
1.1 KiB

using System;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class HealthState : MonoBehaviour, INetworkSerializable
{
[NonSerialized] public float health = 100;
[NonSerialized] public float maxHealth = 100;
[NonSerialized] public int deathTick;
[NonSerialized] public Entity killedBy;
public void Serialize(ref NetworkWriter writer, IEntityReferenceSerializer refSerializer)
{
writer.WriteFloat("health", health);
}
public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick)
{
health = reader.ReadFloat();
}
public void SetMaxHealth(float maxHealth)
{
this.maxHealth = maxHealth;
health = maxHealth;
}
public void ApplyDamage(ref DamageEvent damageEvent, int tick)
{
if (health <= 0)
return;
health -= damageEvent.damage;
if (health <= 0)
{
killedBy = damageEvent.instigator;
deathTick = tick;
health = 0;
}
}
}