I can set up a GameObject cube, and convert it to an entity using authoring component scripts. With this, I can write a script that does a raycast on click. When I do this, the raycast works correctly.
However, I want to create that component in the script, and not have to use the authoring component conversion workflow.
The objects I am trying to spawn are spawned in random positions on each startup, so I don’t want to have them all created in the hierarchy, just so they can be converted. How do I create an entity, WITHOUT conversion components in the editor, that will register the raycast?
andrew-lukasik had a great comment above.
By creating a “Bounds”, using the “WorldRenderBounds” of each entity queried, an IntersectRay can be run to determine if the mouse-click intersected the entity.
if (Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Entities.ForEach((Entity entity, in WorldRenderBounds bounds) => {
float3 center = bounds.Value.Center;
float3 extents = bounds.Value.Extents;
Bounds newBounds = new Bounds(center, extents);
bool haveHit = newBounds.IntersectRay(ray, out float distance);
if (haveHit)
{
Debug.Log("Click registered hit");
}
}).Run();
}
}