Posted on

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.

Posted on

Random Range Not Working in Unity

If you are ever trying to get a random number between 0 and 1 in Unity and end up only ever getting 0 then this might be your problem and solution. One thing you might not know about Random Range function in Unity is that the second parameter needs be plus one greater than the top number you wish to have for random pick 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.

Posted on

What is a Kinematic Rigidbody in Unity

For this short Unity Lesson, I teach you what the is Kinematic option does on the Rigidbody component in Unity. The is kinematic setting makes it so that the rigidbody object will not move because of Physics.

Now you might be wondering, why would you want to attach a rigidbody component to an object only to disable to physics of the object? The answer is that sometimes you want an object to be stationary until a certain point and only after something happens do you want the object to interact with physics. At that point, all you have to do is disable the is kinematic option.

For example in my Zig Zag tutorial series I want the platforms to eventually fall but not until that ball touches the platform and then leaves the platform. This will then make it look like all the platforms are falling just behind the ball.