I am a beginner to Unity C#, but not C# itself. I have seen this topic several times here but none seem to answer my questions, PLEASE help! This class is the location of the error.
using UnityEngine;
using System.Collections;
public class WorldGen : MonoBehaviour {
private BlockManager blockManager;
private int width = 64;
private int height = 128;
private Block[,] blocks;
public GameObject GameManager;
private void Start()
{
blockManager = GameObject.Find("GameManager").GetComponent<BlockManager>();
blocks = new Block[width, height];
GenerateBlocks();
SpawnBlocks();
}
private void GenerateBlocks()
{
for (int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
blocks[x, y] = blockManager.FindBlock(2);
}
}
}
private void SpawnBlocks()
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
GameObject blockGO = new GameObject();
SpriteRenderer sr = blockGO.AddComponent<SpriteRenderer>();
sr.sprite = blocks[x, y].sprite;
blockGO.name = blocks[x, y].display_name;
blockGO.transform.position = new Vector3(x, y);
}
}
}
}
Originally I had followed a tutorial exactly as far as I could tell, but they did not get this error, and I did.
Tutorial: