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!
9 Réponses
+ 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];
}
}
}
+ 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;
}
}
}
+ 3
I’m not 100% sure what you mean. Could you give me an example of what you’re working on?
+ 2
Omg, thank you! You are genius and you save me!!! Thank you a lot!
+ 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.
+ 1
Thank you a lot. But if i want to change 9 sprites, what would i do?
+ 1
Sorry, but its actually not working. Or i dont understand that, or i made a mistake, or you made a mistake
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.
0
There is 5 mistakes and this isnt work. All in all, thank you. I'll come up with something