V
V
valek972020-09-03 19:38:08
Unity
valek97, 2020-09-03 19:38:08

How to change the color of a sprite?

I have an object. It has a basic png format sprite. I want to change color when hovering the mouse over it. I found a video where the color change is done, but something doesn’t work for me. There is no reaction when hovering over the sprite. A 2D box collider hangs on the object, the script is responsible for changing the color. I tried to change the color both through the code and through the inspector field, there is no reaction. The code is handled by the click event and the click exit. (code from the script). Changing the material will not help me here, because I'm working with a sprite.

void OnMouseEnter()
    {   
       if (!isGround)
GetComponent<SpriteRenderer>().color = CurrColor;
}
void OnMouseExit()
    {
        GetComponent<SpriteRenderer>().color = new Color(1, 0, 0); ;
    }

5f511ca41aed2690136804.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2020-09-04
@WasTabon

public GameObject obj

void OnMouseExit()
    {
       obj.color = new Color32(0, 0, 0, 0);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question