-2
\$\begingroup\$

I read the answer of Change the sprite of a Object in Unity but I can't seem to make Unity to understand what to do. visual studio can handle the code but as it says drag the sprite to the code don't work and i can't add the sprite to the code.

\$\endgroup\$
  • \$\begingroup\$ It seems like your specific question is "how do I do this thing this other question asks, I do not understand". You can ask for clarification or post a bounty on questions to seek better answers, but by deliberately asking the same question, this is nothing but a deliberate duplicate. \$\endgroup\$ – Gnemlock Oct 9 '16 at 22:27
  • 2
    \$\begingroup\$ Possible duplicate of Change the sprite of a Object in Unity \$\endgroup\$ – Gnemlock Oct 9 '16 at 22:27
  • \$\begingroup\$ Did you just copy-pasted the code on an empty script file ? It doesn't work that way. You also have to add using statements, and put the code in a class. \$\endgroup\$ – Stavros D Oct 10 '16 at 10:53
-1
\$\begingroup\$

Make a public Sprite object. Assign a picture/sprite to this in the editor. In your code, somehow have a reference to your character's sprite renderer (GetComponent<SpriteRenderer>()'), which you can then set thesprite` value of to your public Sprite that you already defined. An example (pseudo-code):

public Sprite spriteToChangeTo;

void Update(){
if(Input.GetKeyDown(Keycode.Space)){
GetComponent<SpriteRenderer>().sprite = spriteToChangeTo;
}
}
| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.