【问题标题】:Unity Legacy Shader how to change decal from scriptUnity Legacy Shader 如何从脚本更改贴花
【发布时间】:2019-06-03 20:34:42
【问题描述】:

这是我正在使用的,但我在网上找不到任何关于如何更换贴花的信息。

假设我有多个纹理 ex.(Tex1、Tex2、.. 等)。

  • 如何在脚本中访问 _DecalTex 以便分配不同的纹理?
  • 如果按钮选择 Change _DecalTex == Tex2,应该有一些我不知道或尚未找到的简单方法,任何帮助或链接都会有所帮助谢谢 :)

【问题讨论】:

    标签: unity3d shader decal


    【解决方案1】:

    如果您查看LegacyShaders/Decal(state Unity 2017.2) 的源代码,您会看到要更改的属性称为_DecalText

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

    您可以简单地使用material.SetTexture进行设置

    material.SetTexture("_DecalTex", texture);
    

    例如喜欢

    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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多