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. Dismiss Notice

Increasing Emission Intensity of an Individual Object

Discussion in 'Scripting' started by Thrazamund, Jan 16, 2021.

  1. Thrazamund

    Thrazamund

    Joined:
    Apr 14, 2017
    Posts:
    36
    Hello,

    I've seen there is a way to increase the emission intensity of a material at runtime using a script. Is there any way to increase the emission intensity of a single object and not all objects using that material? For instance, if I have an enemy with an emissive eyes material and I want all enemies' eyes to flicker intensity at different times. Or do I have to create individual materials for each?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
    In code, if you use and modify the
    material
    property of a Renderer, it will create a new unique material for that renderer and therefore you will only modify the material for that one renderer.

    If you use the
    sharedMaterial
    property, it will change the material that all the objects using that material are sharing, and thus modify all of them.

    Please read the documentation for more information:
    https://docs.unity3d.com/ScriptReference/Renderer-material.html
    https://docs.unity3d.com/ScriptReference/Renderer-sharedMaterial.html
     
  3. Thrazamund

    Thrazamund

    Joined:
    Apr 14, 2017
    Posts:
    36
    That's very helpful, thank you!