I want to let my users add a image to a folder in the game, which the game loads and applies to a material, I can get this to work in the editor with resources.load but I cannot change the image once it is built.
Notes:
I need to edit the second element on a skinned mesh
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class loadflag : MonoBehaviour {
Material modiable_mat;
public Texture user_tex;
void Start () {
user_tex = Resources.Load<Texture2D>("mods/flag_symbol");
modiable_mat = GetComponent<Renderer>().materials[1];
//load custom decals
modiable_mat.SetTexture("_DetailMask", user_tex);
modiable_mat.SetTexture("_DetailAlbedoMap", user_tex);
}
}
Solved it
You can use WWW.LoadImageIntoTexture and replace http://www.yyyy.xxxx/zzzz with file://yourfile
example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class loadflag : MonoBehaviour {
Material modiable_mat;
Material back;
public int player;
string Path;
public Texture2D user_tex;
public WWW w;
// Use this for initialization
void Start () {
Path = Application.dataPath;
Path = "file://" + Path + "/Resources/mods/flag_symbol.png"; //Location of your file
modiable_mat = GetComponent<Renderer>().materials[1]; //grab the correct material
w = new WWW (Path); //Doubts load time for local file so no yeild needed
user_tex = w.texture;
//update material to have custom image
modiable_mat.SetTexture("_DetailMask", user_tex); //
modiable_mat.SetTexture("_DetailAlbedoMap", user_tex);
}
}