Resources are lost after building

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)); =;
if (i == str.Length)
i = 0;

“All assets that are in a folder named “Resources” anywhere in the Assets folder can be accessed via the Resources.Load functions. Multiple “Resources” folders may exist and when loading objects each will be examined.”


as mentioned in the previous answer, firstly you need to place your resources in a Resources folder.

Secondly, LoadAssetAtPath only works in the editor, it will not work when the game is compiled.

You will need to create a Folder names “Resources” in the root of your assets foler, then use the following code to load your resource

texture = Resources.Load<Texture2D>(str*);* 

texture = Resources.Load(str*, typeof(Texture2D))*