Unity 2022 entities 物体旋转

该文章展示了如何在Unity2022.3.0版本中利用EntitiesAPI和Burst编译器创建一个名为CubeRotateSystem的系统。该系统遍历并更新具有LocalTransform和RotateSpeed组件数据的游戏对象,根据RotateSpeed的值以Delta时间旋转Cube的Y轴。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Entities v1.0.11

Unity v2022.3.0

参考地址:Iterate over component data with SystemAPI.Query | Entities | 1.0.11 (unity3d.com)

using Unity.Burst; 
using Unity.Entities;
using Unity.Transforms;

[BurstCompile]
public partial struct CubeRotateSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {

    }
    [BurstCompile]
    public void OnDestroy(ref SystemState state)
    {
    }
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {

        float deltaTime = SystemAPI.Time.DeltaTime;
        foreach (var (transform, speed) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotateSpeed>>())
        {
            transform.ValueRW = transform.ValueRO.RotateY(speed.ValueRO.rotateSpeed * deltaTime);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值