看了老版本的的视屏,这种写法一直报错,然后好长时间才搞定,终于不报错了
在场景新建一个物体,加上 DOTS -> ConverttoEntity 脚本
新建一个 移动component 脚本
这个是组件 ,里面只有数据
加上[GenerateAuthoringComponent] 就可以吧这个拖到物体上去,
[GenerateAuthoringComponent]
public class MoveDirection : IComponentData
{
public float Value;
}
新建一个 移动system 脚本
[AlwaysSynchronizeSystem]
public class ZombieMoveSystem : JobComponentSystem
{
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
float deltime = Time.DeltaTime;
Entities.WithoutBurst().ForEach((ref Translation translation, in MoveDirection moveDirection) =>
{
translation.Value += moveDirection.Value * deltime;
}).Run();
return default;
}
// return Entities.WithoutBurst().ForEach((ref Translation translation, in MoveDirection moveDirection) =>
// {
// translation.Value += moveDirection.Value* deltime;
//}).Schedule(inputDeps);
//或者不加WithoutBurst() 目前在entity0.11版本这些之前的写法都会报错,
}
然后运行这个物体就可以动了