- Home /
SetMaterial don't works with canvasRenderer
Hello. I want to add grayscale filter to Image object in Unity UI. I found this grayscale shader. In my code I have created material and tried to use it like this:
image.canvasRenderer.SetMaterial(material, image.mainTexture);
But nothing was changed. Maybe I have to write totally different shader, when I works with canvas objects?
UPD: I rewrote shader with UI/Default as a base, but no effect too. Maybe shaders must be added to UI elements some other way?
Comment
Answer by Raynoko · Feb 13, 2015 at 09:49 AM
try this:
using UnityEngine.UI;
transform.GetComponent<Image>().material = yourMaterial;
Your answer