dimanche 19 juillet 2020

Array doesnt give an Out of bounds Error Message while picking a Random item C#/Unity

I have a beginner question. Why does this code not result in an error message?

public Tile[] tiles = new Tile[2];
...
SetTile(0, 0, 0, nocollide, tiles[Random.Range(0,2)]);

The Array is has two items in it but I pick a value from 0 to two, which are three items. When I make it to 0,1 it just picks the first item. But why?




Aucun commentaire:

Enregistrer un commentaire