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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Code for opacity

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

  1. Lmsmestre


    Sep 22, 2022
    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.

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


    May 8, 2020
    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.