Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Maybe a repeat question: How to make GameObject transparent?

Discussion in 'Scripting' started by mirzahat, Aug 22, 2015.

  1. mirzahat

    mirzahat

    Joined:
    Dec 21, 2014
    Posts:
    53
    Hello

    I found many answers online for this question but none works.

    I try to make my gameobject half visible. Here is what most of them recommend:

    Code (csharp):
    1.  
    2. Renderer ren7 = ball7.GetComponent<Renderer>();
    3. Color dropColor = ren7.material.color;
    4. dropColor.a = 0.5f;
    5. ren7.material.color = dropColor;
    6.  
    It does not work, also, it does not show any errors!

    Any advice?

    Mirza
     
  2. Apfelbox

    Apfelbox

    Joined:
    Apr 28, 2014
    Posts:
    38
    Not all shaders can display transparency. First make a custom material for your gameobject and set the shader to Legacy Shaders -> Transparent -> Diffuse

    From that point you can change the transparency with something like that:
    Code (CSharp):
    1. gameObject.GetComponent<MeshRenderer> ().material.color = new Color(1.0f, 1.0f, 1.0f, 0.4f);
    Hope this helps
     
  3. mirzahat

    mirzahat

    Joined:
    Dec 21, 2014
    Posts:
    53
    Indeed it did help, thanks!