- Home /
Using Texture Assets in Code
I have some sprites in my Assets/Images/ folder which I want to use in dynamically created Orthello 2D Sprites.
Here's the code:
OTSprite os = OT.CreateObject(OTObjectType.Sprite).GetComponent<OTSprite>();
os.position = mPos;
os.additive = true;
os.image=Resources.LoadAssetAtPath("Assets/Images/circle.png", typeof(Texture)) as Texture
Now this works fine when I play in Unity. But when I build & run, the proper sprite is not loaded & I just see the default square sprite.
What's wrong with this?
Is there any other way to use imported sprites at runtime?
Answer by robertbu · Apr 23, 2013 at 12:08 PM
Try putting your assets in the Assets/Resources folder. My guess is that since the the images in Assets/Images are not referenced directly in code, they are not being included in the build. Everything in the Resources folder is included in the build.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Different Views of 2D Sprites 1 Answer
C# How to Check If a Gameobject's tag doesn't equal a Specific Tag 3 Answers
C# Throw GameObject Upon Mouse Click 1 Answer
Player lives script help 1 Answer