Hi Guys, im new in coding in unity
the thing is i just need a little help with some coding
i want some gameObject goes transparent when my player pass behind it
and the only thing i know is this code, but i want to implement it into unity
A GameObject doesn’t have alpha. A GameObject can have a Renderer component, the renderer can have 1 or more materials, each material can have multiple properties (these are different depending on what shader it is using). Any of these properties can be a color, and these color values each have an alpha.
If your renders primary material uses the standard shader, though, you can simply use this function to set the color
Note that even though only want to set the alpha value, the alpha is a property of the color, so you actually need to set the entire color. So copy the renderer.material.color to a local variable, set the alpha of your local variable, then assign the renderer.material.color = your local variable.
Also note that not all materials support this. You’d have to make sure that your material uses a transparent shader, or the alpha adjustment will be ignored.
That’s true. I’m assuming you’re using the Standard Shader, but even then you have to set the Material to use one of the transparent rendering modes or changing the alpha won’t do anything.