- Home /
Question by
dcantarelli · Apr 30, 2014 at 09:57 PM ·
javascriptspriteunity 2dchange
Change a sprite during the game- JS
I'm trying to swipe the enemy sprite, after his death. There's a code which does this in the Unity tutorial, but my entire code is in Javascript. I tried to do the same thing but is not working, and I don't know why.. How do I fix this?
function Death(){
//gets the Sprite renderer of my enemy
ren = GameObject.Find(this.name).GetComponent(SpriteRenderer);
var renderers = GetComponentsInChildren(SpriteRenderer);
//desables all the other past sprites
for(var s : SpriteRenderer in renderes){
s.enabled = false;
}
//and then enables a new one
ren.sprite = DeadSprite;
ren.enabled = true;
}
Unity is not is not changing the Sprite at all..
Comment
Answer by SunriseKingdom · May 01, 2014 at 11:47 AM
Maybe, this will help?
var image : Sprite;
function Start () {
GetComponent(SpriteRenderer).sprite = image;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613143948im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object sprite changes 1 Answer
2d javascript How to change a sprite during runtime 1 Answer
sprite after animation 1 Answer
Unity 2D Sprite is invisible. 2 Answers
How can I instantiate a different sprite depending on where Raycasting goes? 0 Answers