0
votes

Can't use Color on Image component.

Looked for solution but no luck. How can i use color on Image?

Here is the sample code that should work

public void Locked(GameObject go)
{
    Image ima = go.GetComponent<Image>();
    // Below line throws 'Image' does not contain a definition for 'color'
    ima.color = new Color(200,200,200); 
}
2
Make sure you have using UnityEngine.UI; not using UnityEngine.UIElements; ...derHugo

2 Answers

0
votes

There doesn't seem to be anything wrong with that code. Make sure to include

using UnityEngine.UI;

at the top of your script.

0
votes

I don't know why they broke it, but now it works like this: image.material.color=...