- Home /
How to change the entire sprite sheet during runtime
Hey.so basically what i want to achieve is to change the entire sprite sheet during runtime. E.g. Lets say i have a shop with golden armour outfit and leather outfit and if i buy golden armour my Sprite sheets and animations changes to player_golden_outfit or something like that.sorry if you dont get it and sorry i cant upload a script its because im doing this from my phone
Answer by Cherno · Jun 23, 2015 at 12:05 AM
Assign the Sprite to the SpriteRenderer component and the relevant Animation Controller to the Animation component.
Edit:
public RuntimeAnimatorController rta;
public Sprite sprite;
void Start() {
SpriteRenderer sr = GetComponent<SpriteRenderer>();
sr.sprite = sprite;
Animator animator = GetComponent<Animator>();
animator.runtimeAnimatorController = rta;
}
Is it not? I was under the impression that this accurately answers his question, otherwise I wouldn't have posted it. If he would have asked in a more specific way, I would gladly have answered in a more specific way, for example how to write the code for that.
Sorry i didt intend to me mean but it did help. I thought about it for a while and i found a semi way so thanks but can you write :-) a script which would let me change the sprite sheet.thanks in advance
Here you go:
public RuntimeAnimatorController rta;
public Sprite sprite;
void Start() {
SpriteRenderer sr = GetComponent<SpriteRenderer>();
sr.sprite = sprite;
Animator animator = GetComponent<Animator>();
animator.runtimeAnimatorController = rta;
}