简体   繁体   中英

Can't get SetTexture to work

I'm pretty sure this will be an easy fix, but I don't see it. I want to change the texture on the material a projector is projecting. This is what I have

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

Everything used to be at update but even in Start it won't work. The debug logs show that it can find the material and texture, so it has to be something to do with the settexture

Help would be much appreciated

i dont know what you did but this is the example from unity documentation. you can set it to the script of the object that you want to change its texture. _BumpMap is the normal map

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM