Unity3d 动态更换贴图

最近在用Unity做一个3D照片墙,要实现动态切换照片的功能。
在网上找了很久才找到能实现的方法。
版本2021.3.16f1c1

点击查看代码
using System.Collections;  
using System.Collections.Generic;  
using UnityEngine;  
using UnityEngine.UI;  
using System.IO;  
  
public class ChangeFhoto : MonoBehaviour  
{  
    // Start is called before the first frame update  
    int id;  
    Texture t=null;  
    string path="";  
    MeshRenderer meshRenderer=null;  
    void Start()  
    {  
        path= "";//素材路径,在Assets/Resources目录下,不要带后缀
        t=Resources.Load<Texture>(path);  
        gameObject.GetComponent<MeshRenderer>().material.SetTexture("_MainTex",t);  
    }  
  
    // Update is called once per frame  
    void Update()  
    {  
          
    }  
}  
posted @ 2023-01-25 21:53  Makerz  阅读(285)  评论(0)    收藏  举报