I am making a game for Android using Unity 5.4.0f3 and am having trouble fading out a sprite's
color.a value. I have tried animations, but they don't seem to work for me. I have tried using the code from here and here, but those didn't work either. I want the sprite to fade out over about 1 second when it is tapped. I think I need to use a
for loop and
Mathf.Lerp. Please help.
Edit: Here is an image of the Inspector view of the object I want to fade out.
Sprite-Default material is NOT modifiable.
Try this instead:
/* Modify SpriteRenderer.color instead of Material.color */ //Get the renderer via GetComponent or have it cached previously var renderer = GetComponent<SpriteRenderer>(); renderer.color = new Color(0f, 0f, 0f, 0f); // Do your lerping stuff with this property
If you still want to modify Material
Create a new material in
Projecttab and name it whatever you want.
Assign it a shader like in the below image.
Assign the newly created
materialto your Sprite Renderer
Materialslot. Notice that now you can modify material color from the inspector. It has not been grayed out any more. You should run you code again and it should work.