I keep getting this “IndexOutOfRangeException: Array index is out of range.
grassPlain.createHandlerEntry () (at Assets/Scripts/Tiles/Grass/grassPlain.cs:32)
grassPlain.Start () (at Assets/Scripts/Tiles/Grass/grassPlain.cs:21)”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grassHandler : MonoBehaviour {
public class glassPlain {
public bool isOwned;
public bool isBuilt;
public bool isPlagued;
public int population;
}
public grassPlain[] plain;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grassPlain : MonoBehaviour {
// Handler Information
public bool hasEntry;
public int tileNumber;
public bool isOwned;
public bool isBuilt;
public bool isPlagued;
public int population;
// Script Information
public grassHandler grassHandler;
// Use this for initialization
void Start () {
createHandlerEntry ();
}
// Update is called once per frame
void Update () {
}
void createHandlerEntry () {
tileNumber = grassHandler.plain.Length + 1;
grassHandler.plain = new grassPlain[tileNumber];
grassHandler.plain [tileNumber].isOwned = false;
grassHandler.plain [tileNumber].isBuilt = false;
grassHandler.plain [tileNumber].isPlagued = false;
grassHandler.plain [tileNumber].population = Random.Range (0, 100);
Debug.Log (grassHandler.plain [tileNumber]);
}
}
Any help would be appreciated, I've tried several different ways but I always end up with the same result, arrays and raycasting have been my struggles of late.