- Home /
Image UI color not changing when sprite is set via script
This is my code:
public Image image;
public Sprite sprite;
private void Start()
{
image = GetComponent<Image>();
image.sprite = sprite;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
image.color = new Color(1f, 1f, 1f, 0.5f);
}
}
It should change the color of the UI image but it just doesn't. I can see in the editor that the color of the image component is changing, but not the actual image in the scene. Though, when i set the sprite of the image in the editor, it works fine! Am i missing something? If you know, please help. Thanks!
untitled.png
(20.1 kB)
Comment
the code is fine so you must be re-changing the sprite to a default one again somewhere else, try printing in the console the image.sprite and see when this happens
Your answer
Follow this Question
Related Questions
Button image sprite colour change 1 Answer
Erase certain color from sprite 0 Answers
Change the button target image alpha 1 Answer