So I have a scene where the player has to collect some fuses to get the power on. The problem is that all the fuses are destroyed whenever I pick up a fuse in-game. I don’t want to create a separate tag for each fuse, and I want to avoid OnMouseOver due to its jankiness. Is there a way I can keep my fuses tagged the same and avoid OnMouseOver while only destroying the fuse I am trying to pick up?
Here’s the script:
float distance;
[SerializeField] string tagName;
[SerializeField] float reach;
[SerializeField] GameObject playerGuy;
[SerializeField] GameObject interactionImage;
[SerializeField] ItemData _itemData;
[SerializeField] InventoryViewController inventoryData;
void Update()
{
distance = PlayerCasting.DistanceFromTarget;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Transform selection = hit.transform;
if (selection.CompareTag(tagName))
{
if (distance <= reach && !SelectPuzzle.isPuzzling)
{
interactionImage.SetActive(true);
if (Input.GetButtonDown("Interact"))
{
if (!InventoryViewController.inventoryFull)
{
inventoryData.OnPickedUpItem(_itemData);
interactionImage.SetActive(false);
Destroy(gameObject);
}
else
{
return;
}
}
}
}
}
if (distance > reach)
{
interactionImage.SetActive(false);
}
}