So I have everything working fine and found the challenge easy, but I’m not 100% sure how it’s actually working.
So I understand that we rearranged the hits array based on the distance of each raycast.
but in the code where its actually sets the raycastable:
foreach (RaycastHit hit in hits)
{
IRaycastable[] raycastables = hit.transform.GetComponents<IRaycastable>();
foreach (IRaycastable raycastable in raycastables)
{
if (raycastable.HandleRaycast(this))
{
SetCursor(raycastable.GetCursorType());
return true;
}
}
}
Does this work because the foreach for the hits will keep overwriting the previous Iraycastable in the nested Iraycastable array because the Iraycastable that is the closest is a later element in the hits array? that was quite a mouthful hopefully that made sense