I am kind of new to unity coding and I am trying to code a feature for the menu where when you hover over a button it lights up. I am trying to do this with sprite arrays that rely on a bool that depends on wether or not the cursor is colliding with the button causing for it to trigger. The else statement is working but not the if statement. I tried to check if they were on the same z axis and they are, I’ve tried giving them rigid bodies, checking for the trigger function and I don’t think it’s a cursor problem because I’ve tried using other objects to collide with it but it’s still not working. What’s wrong with the code?
public Sprite[] BoxSprites;
public bool IsOver;
// Update is called once per frame
void Update()
{
if (IsOver == true)
{
this.gameObject.GetComponent<SpriteRenderer>().sprite = BoxSprites[1];
}
if (IsOver == false)
{
this.gameObject.GetComponent<SpriteRenderer>().sprite = BoxSprites[0];
}
}
void OnTriggerEnter2d (Collider2D col)
{
if (col.gameObject.tag == "Cursor")
{
IsOver = true;
}
else
{
IsOver = false;
}
}