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

How to Change Shader to cutout at runtime

Discussion in 'Scripting' started by HyarchDev, Feb 2, 2021.

  1. HyarchDev

    HyarchDev

    Joined:
    Feb 2, 2021
    Posts:
    14
    Im too confused and lost on this one can anyone help Change the current shader on a object mesh to cutout and how do you do it? Blend mode? ugh
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Change the .material property on the Renderer for that mesh object.
     
  3. HyarchDev

    HyarchDev

    Joined:
    Feb 2, 2021
    Posts:
    14
    Change it to What tho...

    Code (CSharp):
    1.              n.gameObject.AddComponent<MeshCollider>();
    2.                        n.GetComponent<Renderer>().material.shader = Shader.Find("Standard");
    3.                     n.GetComponent<Renderer>().material = Shader.Find
    4.                     n.GetComponent<Renderer>().material.SetFloat("_Glossiness", 0);
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    The material using the cutout shader ?!

    Generally you don't change the shader on a material. Just make 2 materials each referencing the right shader and swap it out.

    Be sure to understand the relationship between shader, material and all the properties and assets that go into it.