Hi,
Was wondering which way would be more efficient or it doesn’t matter?
if(Input.GetKey(KeyCode.Space) Speed <= SpeedMax){
}
or
if(Input.GetKey(KeyCode.Space)){
if(Speed <= SpeedMax){
}
}
Thanks.
Hi,
Was wondering which way would be more efficient or it doesn’t matter?
if(Input.GetKey(KeyCode.Space) Speed <= SpeedMax){
}
or
if(Input.GetKey(KeyCode.Space)){
if(Speed <= SpeedMax){
}
}
Thanks.
Depends on if both condition need to be checked all the time, because the inside condition will only be checked if the outside condition is true.
Personally - I’ve never seen an in an if statement - that being said - I’m a pretty new bedroom coder and can’t give a professional opinion.
I have been building if statements like your second approach, just making another if loop within the first if loop.
I feel like this is better in the end as you can better organize your code and later have the option to add more operations if you only want the first if to be true.
Is it more memory efficient? I really don’t know.
But my opinion is that it might be a little more organized.
they should be equivalent so go for what you find most readable.
The second part is only be evaluated if the first part passes (which is something you can make use of by doing [null check] [something that’d fail if it was null])