0

How to change sprite after a lot of clicks

Please help me! I dont know, how to change sprite after 50 click on button (character). If you know, it would be very helpful!

2nd Jun 2020, 2:49 PM
KriC Fiv
KriC Fiv - avatar
9 ответов
+ 4
This (I think) will work much better. You can add as many sprites as you want into the array and it should change every 50 clicks: int count = 0; public Sprite[] sprites; //This may be the wrong component, but the correct one should be similar private Renderer renderer; void Start(){ renderer = GetComponent<Renderer>(); } void Update(){ if(Input.getMouseButtonDown(0)) { count++; if(count % 50 == 0){ if(count / 50 < sprites.Length) renderer.sprite = sprites[count / 50]; } } }
2nd Jun 2020, 5:29 PM
Jax
Jax - avatar
+ 5
Are you using the Unity game engine? In that case, something like this might work: int count = 0; public Sprite newSprite; //This may be the wrong component, but the correct one should be similar private Renderer renderer; void Start(){ renderer = GetComponent<Renderer>(); } void Update(){ if(Input.getMouseButtonDown(0)) { count++; if(count == 50){ renderer.sprite = newSprite; } } }
2nd Jun 2020, 2:57 PM
Jax
Jax - avatar
+ 3
I’m not 100% sure what you mean. Could you give me an example of what you’re working on?
2nd Jun 2020, 4:28 PM
Jax
Jax - avatar
+ 2
Omg, thank you! You are genius and you save me!!! Thank you a lot!
2nd Jun 2020, 5:31 PM
KriC Fiv
KriC Fiv - avatar
+ 2
In the editor, you should be able to set the length of sprites. That would be 7 for your game. Then under that, 7 inputs should open up allowing you to drag them (in order) into there. Also, now that I think of it, I believe length should have a lowercase l rather than uppercase L.
2nd Jun 2020, 7:07 PM
Jax
Jax - avatar
+ 1
Thank you a lot. But if i want to change 9 sprites, what would i do?
2nd Jun 2020, 3:42 PM
KriC Fiv
KriC Fiv - avatar
+ 1
Sorry, but its actually not working. Or i dont understand that, or i made a mistake, or you made a mistake
2nd Jun 2020, 6:34 PM
KriC Fiv
KriC Fiv - avatar
0
Look. I am working on clicker and i have download 9 sprites on project. I want to change this sprites every 50 clicks. Like you click on sprite1 50 times and then it change to sprite2. Then you click 50 times on sprite2 and it changed to sprite3 and so on.
2nd Jun 2020, 4:31 PM
KriC Fiv
KriC Fiv - avatar
0
There is 5 mistakes and this isnt work. All in all, thank you. I'll come up with something
2nd Jun 2020, 7:32 PM
KriC Fiv
KriC Fiv - avatar