- Home /
Fading out a transparent material
Usually, the answer to this question is "Use a transparent shader", but I don't think I'm so lucky. :\ I've tried this code with both the Transparent/Diffuse and Unlit/Transparent shaders. I've also copy-pasted some solutions I found online, but none of them worked.
The GameObject is a small plane with a texture that's used to show "You can move to this tile", and after the move, it's meant to fade out. It works perfectly when I make it remove itself, but the fading doesn't work at all. To simplify things, I'm trying to make it set itself to 0.05 alpha while it's alive. Once I get that part, doing a fade will be simple math.
Not sure that it matters, but the texture itself is an RGB png (no alpha channel yet), and the GameObject was instantiated from a prefab. I checked the instantiated objects while in-game, and all their settings looked fine... same transparent shader, correct variables...
Any help will be greatly appreciated :D
pragma strict
var binIchBrauchte : int = 1; var sollIchSchimmern : int = 1; var meinAlpha : float = 1; var posTile : Vector2;
var guiObject : Material; var fadeTime = 1.0; enum Fadee {In, Out}
function Start () { binIchBrauchte = 1; gameObject.tag = "TileBorder"; guiObject = renderer.material; }
function Update () { //guiObject = gameObject.renderer.material; if (binIchBrauchte == 0) { // Fade out, and then destroy myself // Kills the game object Destroy (gameObject); } else if (binIchBrauchte == 1) { if (sollIchSchimmern == 1) { // Alpha channel gameObject.transform.renderer.material.color.a = 0.05; gameObject.renderer.material.color.a = 0.05; transform.renderer.material.color.a = 0.05; renderer.material.color.a = 0.05; } }
Well, I might as well get the basic out of the way first... if you go into the material itself, open the color, and edit the alpha channel, does the material fade?
How do I do that? I see the material, but I don't see any "color" settings...
In Transparent/Diffuse, the first setting is "$$anonymous$$ain Color". There will be a rectangle to the right (probably white). Click that, and slide the "A" value back and forth.
Ah, I was in Unlit/Transparent. I tried Transparent/Diffuse, and the code works now.
Tbh, I'm not sure what happened, because I tried Transparent/Diffuse right before posting this question. I did simplify the code a bit, so maybe I had an error when I tested.
Sorry to waste your time - I guess the solution really WAS "use a transparent shader" :P
Also, if you copy-paste your comment as an answer, I'll choose it as the answer. Thanks for the help! :D
Answer by Screenhog · Sep 25, 2012 at 05:37 PM
In Transparent/Diffuse, the first setting is "Main Color". There will be a rectangle to the right (probably white). Click that, and slide the "A" value back and forth.
Your answer
Follow this Question
Related Questions
Fading out doesn't fade out, but instantly goes from black to clear 0 Answers
Fading all but single instance of a button 1 Answer
Fade In/out issue about a gameobject 0 Answers
Shader is not displaying alpha correctly 0 Answers
Alpha not displaying when changed in code, unless changed manually in the inspector 0 Answers