0

This is what I am using but I can't find anything online regarding how to go about changing out a decal.

Let's consider that I have multiple Textures ex.(Tex1, Tex2, .. etc).

  • How could I access the _DecalTex in script so I can assign different textures?
  • Like if button selected Change _DecalTex == Tex2, there should be some simple way I just dont know about or have found yet, any help or links to this would be helpful Thanks :)

Edric
  • 24,639
  • 13
  • 81
  • 91
user3277468
  • 141
  • 2
  • 11

1 Answers1

1

If you look at the source code of LegacyShaders/Decal(state Unity 2017.2) you see that the property you want to change is called _DecalText

Shader "Legacy Shaders/Decal" 
{
    Properties 
    {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _DecalTex ("Decal (RGBA)", 2D) = "black" {}
    }

    ...
}

You can simply set it using material.SetTexture

material.SetTexture("_DecalTex", texture);

e.g. like

public class Example : MonoBehaviour
{
    // reference in the Inspector
    public Texture texture;

    private void Start()
    {
        var renderer = GetComponent<MeshRenderer>();
        var material = renderer.material;

        material.SetTexture("_DecalTex", texture);
    }
}

enter image description here

derHugo
  • 83,094
  • 9
  • 75
  • 115