- Home /
How to add sprites to a canvas via scripting
How do you add sprites to a canvas through code? Especially if the sprites are attached to a game object. Would really appreciate an answer to this considering I want to code GUI stuff and want to use the new canvas to do so.
Comment
Answer by Notter · Jun 08, 2015 at 09:16 AM
You need to have/create a GameObject with the an Image component. and in your code you can do this:
myGameObject.GetComponent<Image>().Sprite = YourSprite;
Your answer
Follow this Question
Related Questions
uGUI Mask Content 0 Answers
Get texture/material from UI canvas 0 Answers
Problem in text 3 Answers
Sprite renderer vs image renderer issues on canvas 1 Answer
I ask one thing about resizing with different resolution. 1 Answer