Unity加载本地图片并动态替换图片材质

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27124771/article/details/82108883
public Material splash;//图片材质
private void Awake() {
    StartCoroutine("LoadImg");
}
IEnumerator LoadImg() {
    //打包后生成的exe所在路径
    string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    string fileName = "pic.jpg";//图片名称
    WWW wwwTexture = new WWW("file://"+path+fileName);
    yield return wwwTexture;
    if(wwwTexture.texture != null) {
        splash.mainTexture = wwwTexture.texture;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_27124771/article/details/82108883