Having trouble with an if statement {unity+fmod} | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having trouble with an if statement {unity+fmod}

I'm having trouble trying to figure out how to make a sound effect only play once for every hundred score points. at the moment I'm using: if (score % 100 == 0 && score !=0) { eventEmitter.Play(); } but obviously this causes the sound to continuously play while the player is on every hundred. is there a way to only make it play once? maybe a different execution all together?

29th Oct 2018, 9:36 PM
Rute Gomes
Rute Gomes - avatar
1 Answer
0
A simple way would be to store the previous score in a variable, then only play when it didn't reach 100 points. Like: if (score % 100 == 0 && previous_score % 100 != 0) { eventEmitter.Play(); previous_score = score; }
29th Oct 2018, 11:47 PM
Emerson Prado
Emerson Prado - avatar