- Home /
Can't get various different sprites to change on a UI *Image*.
Okay, so I have three sprites called 'gold', 'silver' and 'bronze', which are in a folder called resources, and are already as 'Sprite 2D and UI'. Basically, I have a car which collides with a finish line and detects the trigger entry, sending a message to execute a function called 'Finished()' on another script.
Now, since the game has finished and the player has crossed the line, I want to give the user a 'Results' window/canvas to show how they did e.g. Gold, silver, bronze. I have two UI images which should display the correct sprite, based on score and time. I have already dragged and dropped the correct items in the inspector, I cannot show that action since no more photos are allowed on this particular post. Here's the code I have so far which doesn't work.
Referencing & 2. Instantiating:
Execution:
I have worked it out....
public Transform myUiImage; // The rect-transform of the UI image (Drap from inspector). public Sprite mySprites; // The sprites (Drap from inspector).
void FunctionToRun() { myUiImage.GetComponent().sprite = mySprites; }
Your answer
Follow this Question
Related Questions
compress photos on import 0 Answers
Draw a Sprite Round 1 Answer
UI Image has no sprite definition 0 Answers
Image vs Sprites performance 1 Answer
Possible to use sprite mesh for UI.Image GraphicRaycaster culling? 1 Answer