Search Unity

Code for opacity

Discussion in 'Scripting' started by Lmsmestre, Sep 26, 2022.

  1. Lmsmestre

    Lmsmestre

    Joined:
    Sep 22, 2022
    Posts:
    4
    Dear All,
    I'm looking for some help with c# for the following:
    - I have a scene with an object and want to be able to remove opacity with a slider in order to see thru.

    Regards
    Luis Mestre
     
    Last edited: Sep 28, 2022
  2. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    348
    When you say object, I'd guess you mean a mesh with the standard material on it?

    Make a new material in your project, drag it on to the object, select Surface Type: Transparent from the drop down boxes on the material.

    This already has a slider if you click the base color on the material, and move the alpha slider.

    If you want to change the material color via script, get a reference to the object's material via the Renderer component and set its .color property to whatever you want. Add the Range attribute to a public field to make it a slider if you one on your C# script.