- Home /
Changing sprite of a different object with a button
I am making a bestiary inventory system, and on the left there's the item's and on the right there's the big item and description. I know how to change the text/description although the image is not changing. I tried it with sprites (SpriteRenderer) and it didn't work, but I can't figure out to test it out with images. 
Answer by MickyX · May 06 at 11:23 PM
Create a reference to the Sprite
//The Image Component in the UI
public Image icon;
//The Sprite from your resources
public Sprite image;
and set it with
icon.sprite = image;
That should do it
Like this? Image says "CS0246: The type or namespace 'Image' could not be found (are you missing a using directive or an assembly reference?)
Wait that might just be because I forgot to add using UnityEngine.UI; 
Add
using UnityEngine.UI;
to the top of your script
Your answer
Follow this Question
Related Questions
How to code Scorpion Mechanic? 0 Answers
Creating one class or using polymorphism? 1 Answer
Object not responding to OnTriggerEnter() 2 Answers
Why doesn't my object move left? 1 Answer
IEnumerator Loop on keypress 1 Answer