So, I'm trying to make a system where you can pick up items by simply clicking on them from a given distance. The problem is that no matter what I tried with a Physics.Raycast, it will always check for ALL of the objects in the given raycast. In cases where I line myself up with a line of items, I end up picking everything up in the given range.
Here's the code I'm working with:
{
if (hit.transform == base.transform && Input.GetMouseButton(0))
{
if (gc.CheckInvSize() != 8)
transform.gameObject.SetActive(false);
else if (gc.item[gc.itemSelected] == 22)
durability = gc.itemDurability[gc.itemSelected];
this.gc.CollectItem(GetID(item), this);
}
}
Is there a way to have the raycast only detect the first object it collides with?