尝试测试Unity3d简单混合实体组件系统。 坚持执行ForEach
一共有三个脚本,第三个是问题
// ------------------------ //
using UnityEngine;
public class CupsuleParams : MonoBehaviour
{
public float speed = 3;
}
// ----------------------- //
using UnityEngine;
public struct CupsuleComponent
{
public Rigidbody rigidbody;
}
// ----------------------- //
using UnityEngine;
using Unity.Entities;
public class CupsuleSystem : ComponentSystem
{
protected override void OnUpdate()
{
// used to be correct before update of the ETC. And all the internet lessons do this way
//foreach (CupsuleComponent component in GetEntities<CupsuleComponent>())
//{
// component.rigidbody.AddForce(Vector3.up);
//}
// this shows error
Entities.ForEach((Entity entities, CupsuleComponent component) =>
{
component.rigidbody.AddForce(Vector3.up);
});
}
}