Hello,
I have a sprite in a folder called “Sprites” in the Assets folder. I want a variable in my script to be assigned that sprite on start, however, I’ve run into a problem. Here’s my current script, how do I fix it?
void Start()
{
nameOfSprite = Resources.Load("NameOfSprite", typeof (Sprite)) as Sprite;
} //this is the broken part, for some reason it won't load the sprite.
void Update()
{
GameObject gameObject= GameObject.Find("GameObject");
gameObject.GetComponent<SpriteRenderer>().sprite = nameOfSprite;
//there should be no problems with this part, I've used it in the past and it worked just fine.
}
I’ve used placeholder names, hope you don’t mind.
Thanks.