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

Fix Index Out of Range Error in Unity

For this lesson, we will teach you how to debug the runtime error, index out of range. If you are receiving this error whether in Unity or with another programming language, you can follow the guidelines in this video to fix this problem. This error occurs when you are trying to access an element of an array that does not exist. As long as the index by which you access your array is with the range of your array you should not be receiving this error.