Question by
shadowpuppet · Jul 11, 2020 at 04:10 PM ·
saveloadstrings
trying to save and load a texture
Already succeeded by assigning all the possible textures an int, saving the int to player prefs and then loading the int and assigning the corresponding texture to that int. But there are a LOT of textures and the script is huge and ugly. So I tried doing it with a string. I can get the name of the texture that is being saved and saving that and I can get the string name of that texture , but how convert that string name of the texture to the actual texture to load on the model? The version in LoadOutfit in the attached script is just one of many failed attempts
using UnityEngine;
using System.Collections;
public class testTextureLoad : MonoBehaviour {
public GameObject skirtMesh;
public Texture skirt;
public string skirtTexture;
public string newSkirtTextureString;
public Texture savedSkirt;
void Update () {
skirt=skirtMesh.renderer.materials [0].mainTexture;
skirtTexture = skirtMesh.renderer.materials [0].mainTexture.name;
}
void SaveOutfit(){
PlayerPrefs.SetString("Skirt", skirtTexture);
savedSkirt.name=PlayerPrefs.GetString("Skirt");
}
void LoadOutfit(){
skirtMesh.renderer.materials [0].mainTexture= savedSkirt;//Here is the Problem - Loading it
}
}
Comment