创建一个子弹结构体
public struct BulletMove : IComponentData
{
public float MoveSpeed;
public float ExistTime;
}
创建子弹移动系统
创建一个子弹生成时间,遍历拥有这些结构体的组件,并操纵这些实体!
private readonly float LifeTime = 5f;
protected override void OnUpdate()
{
Entities.ForEach((Entity e, ref BulletMove bulletMoveSpeed, ref Translation transform, ref LocalToWorld lw) =>
{
transform.Value += (float3)Vector3.Normalize(lw.Forward) * bulletMoveSpeed.MoveSpeed * Time.DeltaTime;
Debug.Log(bulletMoveSpeed.ExistTime + " : bulletMoveSpeed.ExistTime ::");
if(UnityEngine.Time.realtimeSinceStartup - bulletMoveSpeed.ExistTime > LifeTime)
{
EntityManager.DestroyEntity(e);
}
});
}
生成一定数量的实体
public Mesh m_mesh;
public Material m_material;//这里写好后记得出去给这两个玩意儿赋值
private void Update()
{