- Home /
How do i change SpriteRenderer.Sprite
I need a JAVASCRIPT code to change a sprite of an object.
Component:
Answer by ironblock · Jul 26, 2014 at 08:16 AM
language doesn't matter in this case. if i give you the direct answer you wont learn from it. this is something quite simple. but you need to learn how to get components from other objects/scripts.
i don't really like java. its quite messy in my eyes. so il just give you some sudo code. you can convert this easily to your syntax
// better if its in a list or array but this will do fine for now
public GameObject sprite1;
public GameObject sprite2;
gameObject.getcomponent<spriteRenderer>().sprite = sprite1;
Answer by Fabulous-Design · Jul 26, 2014 at 08:43 AM
Found it my self thanks for help:
var sprite1: Sprite;
GetComponent(SpriteRenderer).sprite = sprite1;
wy would you down vote me than ?. my awnser is stil correct. just a different syntax.
Your answer
![](https://koobas.hobune.stream/wayback/20220613155016im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers
How to make a UI image change sprite through a script that is not attached to the UI image itself 0 Answers
When I load image it dissapears 2 Answers
Possible to use sprite mesh for UI.Image GraphicRaycaster culling? 1 Answer
How to make a Line Renderer thin out only near the ends? Alternatively, how to apply 3-way slicing? 1 Answer