无法使SetTexture工作

时间:2015-02-12 15:44:27

标签: c# unity3d

我很确定这将是一个简单的修复,但我没有看到它。 我想改变投影仪投影材料的纹理。 这就是我所拥有的

using UnityEngine;
using System.Collections;

public class ShowPresentation : MonoBehaviour {
    private GameObject SceneProjector;
    private Material proj;
    public Texture2D NewTexture;

    void Start () {
        SceneProjector = GameObject.FindGameObjectWithTag("Projector") ;
        proj = SceneProjector.GetComponent<Projector>().material;
        NewTexture = Resources.LoadAssetAtPath ("Assets/Textures/Wood.tga", typeof(Object)) as Texture2D;
        proj.SetTexture("_MainTex", NewTexture);
    }


    void Update () {
        Debug.Log (proj);
        Debug.Log(NewTexture);
        }
}

过去所有东西都在更新,但即使在开始它也无法正常工作。 调试日志显示它可以找到材质和纹理,因此它必须与settexture有关

非常感谢帮助

1 个答案:

答案 0 :(得分:0)

我不知道你做了什么,但这是Unity文档的例子。您可以将其设置为要更改其纹理的对象的脚本。 _BumpMap是法线贴图

public Texture bumpMap;
renderer.material.SetTexture("_BumpMap", bumpMap);