Is it okay that I did it this way?

While it is totally valid code, there is no point. The first switch only has one case and you made it harder to read (it took me 2 or 3 reads before I realised you have a switch inside another switch).

But, to answer your question; yeah, it will work


Welcome to our community! It’s great to see that you develop your own solutions. :slight_smile:

I agree with what bixarrio wrote. While the inner switch is fine, the outer switch goes against the typical coding conventions. A switch with just one condition should rather be written as an if-statement. I had to read bixarrio’s answer to notice that there is a second switch because my brain swapped out the first switch with an if when I read your code first.

When writing code, it is usually better to stick with the conventions because that’ll make it easier/faster to read and interpret it. Most people simply don’t have time to read code line by line, so they skim it. Of course, if you never intend to show other people your code or to seek help with your code, you can write it in accordance with your personal preference because you will be the only one who will read and interpret it.

That being said, please keep developing your own solutions. In many cases, there are multiple ways to make things work in Unity, and your solution could be equally good as Rick’s or Gary’s, or even better than theirs. :slight_smile:

See also:

Privacy & Terms