- Home /
Button image sprite colour change
Hello world,
I have a small problem: I want a button the light up in a certain colour for a while after I press it. Since I use a custom sprite as the image of the button, influencing the button image colour directly causes it to turn invisible for some reason (rbga isn't setting it to transparent). It actually turns back to its original colour after the coroutine is executed, it's just teh change that isn't working properly.
Here's the script I'm using and how it looks like:
Script
Gif
As the Image component doesn't work, I wanted to use image.sprite; but since there's no SpriteRenderer on the button, I'm unsure on how to set its colour.
Any help is appreciated. :)
Answer by Cornelis-de-Jager · Jul 13, 2017 at 12:40 AM
You can use image.color.
button.image.color = Color.red;
Hey, thanks for the answer. Unfortunately, it still doesn't work, but it seems to be a problem with the lighting and colour of the sprite in the scene. If I use it on the standard UI button sprite it works, however my custom sprite as the button image remains unaffected. I'll probably replace the sprite with a second variant that has the correct colour ins$$anonymous$$d of changing the colour of the image.
Your answer
Follow this Question
Related Questions
Change the button target image alpha 1 Answer
Image UI color not changing when sprite is set via script 0 Answers
Erase certain color from sprite 0 Answers