- Home /
multiples of score in c#
Hello everyone,I'm sorry for my bad english I have a score and an animation in Unity. I want to play the animation when the score is a multiple of 200, but I don't know how to explain the multiples of 200 in C# please help me thank you in advance
Could you elaborate it a bit like do you want the animation to play when the score is above 200 or when it is a multiple of 200?
hello, I tried to explain in more detail below, thank you
Answer by JustAbhi · Sep 16, 2021 at 12:37 PM
hey @ajanm9387 , Its okay just clarified the question. If thats the case the script should have a reference to the score and animation it wants to check and play. Then it may go something like
int c;
void Update(){
//get score here
if(score>=c ){
c+=199;
//play animation
played=true;
}
}
Hope this helps. Edit: Some typos and i copy pasted some code snippets here. Sorry.
@JustAbhi Bismillahirrahmanirrahim, thank you very much, here is the answer I was looking for, stay happy :)
Answer by Lapraniteon · Sep 16, 2021 at 12:02 PM
You can do this with the modulus (%) operator.
Take your score as an int
public int _score;
// Then check if score is divisible by 200
void Start()
{
if ((_score % 200) == 0) {
// Run your animation
}
}
Hope that helped!
Hello again, I'm sorry, I may have expressed myself wrong because my English is bad, for example, when the score is 200, I want to play the animation once. When it reaches 400, I want to play it again. When it reaches 600, I want to play it again and I want it to go like this until the score is 5000.
hi thank you for the answer but in your code it only works when the score is 200
Answer by saikarthi · Sep 16, 2021 at 11:55 AM
get a score in (int or float).
eg) int score;
if(score%200==0) { //start animation }
hey @saikarthi , what about when the score is something like 199 and increases by two?
in fact, the score you want to say works only when it is 200
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Guitext for score over time. 2 Answers
how do i attach GUITEXT to a prefab 1 Answer
Overwritting score with GUI 1 Answer