Search Unity

Question Is there something I need to do to a material to adjust its alpha?

Discussion in 'General Graphics' started by paddymaxson, Mar 2, 2023.

  1. paddymaxson

    paddymaxson

    Joined:
    Jan 16, 2022
    Posts:
    5
    Hello!

    I'm currently trying to set up a script that makes it so if a raycast between my camera positin and player object position is obscured by a scenery object that said scenery objet becomes semi-transparent. This works if I say change it to not render its mesh at all so I know it's detecting the obstruction

    I thought my script wasn't working (it sets GetComponent<MeshRenderer>().material.color's alpha to 0.5f)
    but I noticed that if I just try to manually change the material alpha in its colour in the inspector it also doesn't become transparent.

    Is there something obvious I'm missing here?



    Cheers

    Paddy
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,632
    Changing the Alpha doesn't do anything unless you are using a shader that supports alpha-based transparency. You'll probably need to change the material out instead of just changing the alpha.
     
    paddymaxson likes this.
  3. paddymaxson

    paddymaxson

    Joined:
    Jan 16, 2022
    Posts:
    5
    Thanks - sorry I'm very new to this and learning as I go so there's lots of fundamental stuff I don't know