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 :)

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.