In this lesson, I teach you the easiest way to flip or toggle a bool variable in C# for Unity. This is done by having your destination variable followed by the equals operator and the exclamation operator in front of the source variable and in this case the destination and the source should be the same variable.
Category: C# Tips
How to Use Random Range in C# for Unity
When coding for Unity in C# the Random.Range function is a very helpful function that I use all of the time. This function can be used to generate random behaviors in your game.
The most important to remember when using the Random Range function is that you must have the second parameter be plus one more than the highest number you wish to include when using ints. The reason for this is that the Random Range function normally uses float and like when you case afloat into an int, whatever decimal numbers you have will be removed never rounding up.