You've successfully subscribed to Hacking with Unity - Learn how to create your own games
Great! Next, complete checkout for full access to Hacking with Unity - Learn how to create your own games
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

How to define and use Random in Unity using C#

How to define and use Random in Unity using C#

Ben Liu
Ben Liu

Random number are quite often used Unity games, it help to create random position of enemies, attack range and so on. There are two main override methods in the Unity:

// public static float Range(float min, float max);
Random.Range(-10.0f, 10.0f);

// public static int Range(int min, int max);
Random.Range(0, 10);

The 1st output will be a float from between -10.0 and 10.0, note that -10.0 and 10.0 are inclusive.

The 2nd output will be an integer between 0 and 10. note that 0 is inclusive but 10 is exclusive.

Ben Liu

Please feel free to contact me if you have any question. <br> https://t.me/NeedoneApp