Trying to replace a sprite in UI Image
I'm trying to change the sprite when I load the image with a scriptable object depending on what faction the image is from.
public Image CrestIcon;
if(faction ==Faction.Demon)
{
CrestIcon.GetComponent<Image>().overrideSprite = Resources.Load<Sprite>("Assets/Resources/Sprite" + "Demon_0");
}
else
{
CrestIcon.enabled = false;
}
The enable and disable work fine, but I cant get the image to load for the factions.
I've also tried CrestIcon.transform.GetComponent<Image>().overrideSprite = Resources.Load<Sprite>("Assets/Resources/Sprite" + "Demon_0");
and the path as ("Assets/Resources/Sprite/Demon_0")
Comment
Your answer
Follow this Question
Related Questions
Why my Image.sprite keeps saying null ?? Help! 0 Answers
How to display a sprite as image? 1 Answer
problem with arrays and image replacment 0 Answers