Hello everyone,
I want to change my gameobjects’ sprites in my game. However, I cannot change the sprite of my object properly. It sounds odd but it only changes if I click to the prefab before I play the scene. If I click to the prefab and it can be seen in inspector, then it changes the sprite of the prefab.
I have several sprites for my objects to create a shop for my game. I check which ones are selected, then I try to apply these changes but it is not working. This is my first entry in this forum, so I could make a mistake while creating this post, so please forgive me if I had a mistake.
Here is my code,
for (int i = 0; i < shop.shopsText.Count; i++)
{
//if (bilgi.profileText.head == shop.shopsText[i].id)
//{
// ChangeHead(shopImage[i+1]);
//}
if (bilgi.profileText.body == shop.shopsText[i].id)
{
ChangeBody(shopImage[i + 1]);
}
if (bilgi.profileText.bg == shop.shopsText[i].id)
{
ChangeBG(shopImage[i+1]);
}
if (bilgi.profileText.weapon == shop.shopsText[i].id)
{
ChangeWeapon(shopImage[i+1]);
}
}
void ChangeBody(Sprite img)
{
Head.GetComponent<SpriteRenderer>().sprite = img;
}
void ChangeWeapon(Sprite img)
{
Weapon.GetComponent<SpriteRenderer>().sprite = img;
}
void ChangeBG(Sprite img)
{
BGSkin.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite = img;
}