- Home /
c# if function not finding anything to call
this is part of my script private void MissedBall() {
if (Lives.curlives-- < 1)
}
private void Gameover() { }
below "if(lives.curlives-- < 1)" im trying to type gameover but it can't find it or anything else to call. what am i doing wrong, thanks
Answer by whydoidoit · Jul 15, 2012 at 02:35 PM
You have no body to that if() statement you need
if(Lives.curlives -- < 1 ) {
//Do something here
}
additionally keep in $$anonymous$$d that variable--
is the post decrement operator. So the value is compared and then decremented. So when this condition becomes true the value will be "-1" and not "0"
In such cases it's better to use the pre-decrement operator. Also naturally it's more readable if you write <= 0
ins$$anonymous$$d of < 1
if(--Lives.curlives <= 0 ) {
//Do something here
}
Damn, i hate this new bug...
Definition of update: remove old bugs and implement new ones.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074212im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# Coding error 1 Answer
MonoDevelop Resizing 1 Answer
Ref modifier 1 Answer
A node in a childnode? 1 Answer
Problems with instantiation... 1 Answer