Reputation: 3
I'm making a kind of space-shooter game which has a simplistic geometric style. I got a scrolling background and put it in as a quad. The scrolling background works, but I thought it was a little to bright so I wanted to change the opacity when I realized. "Oh wow, I'm a stupid brain new developer, and I don't know anything about quads or 3D repeating textures and how they behave in a 2D game, since all I've been doing is following a tutorial on how to implement a scrolling background." So I just need some simple code that will change the transparency of my quad.
Upvotes: 0
Views: 2485
Reputation: 94
First step you should change the material rendering mode "the material which assigned to quad or any 3d model " change it to Fade or transparent
Now You Can change the opacity of the color on material this will be applied
Second Step change color from code just you need a reference for MeshRenderer Component
public MeshRenderer quad; // quad to change its opacity
public void setOpacity(float opacity)
{
Color oldColor = quad.sharedMaterial.color; // old color
// now will set old color but with new opacity
quad.sharedMaterial.color = new Color(oldColor.r,oldColor.g,oldColor.g,opacity);
}
Upvotes: 1