Hello,
I have code that works fine in the editor, but after compiling all the textures added from the code is lost.
Can I do something wrong?
public class Sprite123 : MonoBehaviour {
SpriteRenderer newSprite;
Texture2D texture;
string[] str = new string[] { "Assets/Image/icon-bi60x60.jpg", "Assets/Image/2.jpg", "Assets/1.png" };
int i = 0;
void Start()
{
newSprite = GetComponent<SpriteRenderer>();
}
public GUIStyle customButton;
void OnGUI()
{
GUI.Box(new Rect(10, 10, 100, 90), "Loader Menu");
if (GUI.Button(new Rect(20, 40, 80, 20), "Add"))
{
newSprite.sprite = SpriteRenderer.Instantiate(newSprite.sprite)as Sprite;
texture = (Texture2D)Resources.LoadAssetAtPath(str*, typeof(Texture2D));*
newSprite.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f,0.5f));
newSprite.sprite.name = texture.name;
i++;
if (i == str.Length)
{
i = 0;
}
}
}
}