I am learning to create a 2 dimensional array of 100x100 and input random number 1 and 0 into it then use gizmos to display the result. The code roughly demonstrate what I trying to do but it is not working and I failed to spot the mistake. Would appreciate ideas or hints on how to edit the code and point out the error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
int x;
int y;
public int[,] array1;
// Start is called before the first frame update
void Start()
{
for (x = 0; x < 100; x++)
{
for (y = 0; y < 100; y++)
{
array1[x, y] = Random.Range(0, 2);
Debug.Log(string.Format("{0},{1},{2}",x,y,array1[x,y]));
}
}
}
void OnDrawGizmos()
{
if (array1[x, y] == 1)
{
Gizmos.color = Color.black;
}
else
{
Gizmos.color = Color.white;
}
}
}