I’m fairly new to this, so I apologize if this is a really dumb question: Is it OK to do this with an if/else combination, or is this a coding no-no? Specifically, the “do nothing” portion of it in order to nest another if/else in the else:
//If stars left to collect, collect1UI is visable, otherwise it is not.
if (star1off == true) {
//do nothing.
}else{
if (collectOne - collectedOne >= 1) {
var go = GameObject.Find ("Collect1UI");
go.SetActive (true);
} else {
var go = GameObject.Find ("Collect1UI");
go.SetActive (false);
star1off = true;
starOneName = "empty";
}
}
I probably should put this in a comment, but I probably won’t recognize it in my email unless I make it in my own answer.
Is it wrong ?
Is it weird ?
No, the answer to both of them is no. As long as you are happy with it and it has no errors, nothing should stop you with it. I mean who knows, you might be able to include something in there sometime.
But for right now, if you’re happy with it, just leave it. I mean I get what other people will say with “No” and “Its weird and unorganized so don’t do it” and my reply to that is : If you know where everything is, then that’s arguments are kinda invalid.
I alone usually use alot of empty if’s statement for no reason, I’m not home at the moment but if you reply to this answer asking, I will show you.
In addition I saw you added that you are new so lemme just say: Welcome !
and good luck in your projects
You can always do:
if (!star1off) {
if (collectOne - collectedOne >= 1) {
var go = GameObject.Find ("Collect1UI");
go.SetActive (true);
} else {
var go = GameObject.Find ("Collect1UI");
go.SetActive (false);
star1off = true;
starOneName = "empty";
}
}
The ‘!’ just negates the star1off, so if it’s true, !star1off will be false.
It’s better to not leave an empty ‘if’ just to use an else statement, but if you understand better the if statement leaving it empty, go ahead!