该项目的目的是同时测试和演示来自 Unity DOTS 技术堆栈的多个新包。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

36 行
808 B

using System;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.NetCode;
[Serializable]
public struct HealthStateData : IComponentData
{
[GhostDefaultField(1)]
[NonSerialized] public float health;
[NonSerialized] public float maxHealth;
[NonSerialized] public int deathTick;
[NonSerialized] public Entity killedBy;
public void SetMaxHealth(float maxHealth)
{
this.maxHealth = maxHealth;
health = maxHealth;
}
public void ApplyDamage(DamageEvent damageEvent, int tick)
{
if (health <= 0)
return;
health -= damageEvent.Damage;
if (health <= 0)
{
killedBy = damageEvent.Instigator;
deathTick = tick;
health = 0;
}
}
}