Answer the question
In order to leave comments, you need to log in
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); ;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question