Hello,
I am trying to compare an enum type name to a tag in a check inside my code.
How can I do this successfully?
Here is my code:
public enum InteractableType { Enemy, ItemPickup }
public class Interactable : MonoBehaviour {
public InteractableType interactableType;
}
public class MouseScript : MonoBehaviour {
Interactable focus;
void Update ()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100))
{
// Check if we hit an interactable
focus = hit.collider.GetComponent<Interactable>();
if(focus != null)
{
for (int i = 0; i < cursorList.Count; i++)
{
if (focus.interactableType.ToString == cursorList[i].tag)
{
SetCursorTexture(cursorList[i].cursorTexture);
return;
}
}
}
}
// If the raycast does not return anything, we set the default cursor
SetCursorTexture(cursorList[0].cursorTexture);
}
}
Thank you!