Hello,
I have a grid in which the user can place items, and lists are created whenever items of the same type are placed next to each other. Due to the grid size, many of these lists are dynamically created, and then stored in another larger list. The items can be destroyed during play, and these need to be removed from the lists so the count can be updated. So basically, I need to remove null items from lists inside a list, but cannot do so with a for each method because it cause an enumeration error. Any suggestions appreciated, I'm sure the answer is simple and I just don't know what I'm doing.
Thanks.
Below is the full script requested. Im all too aware of the innefficent techniques used, but time restraint prevents me from rescripting. Update() contains the start of what I'm trying to implement. It will be moved to its own function, but update is easiest for testing. I want to check each List in listOfShipLists for empty values and remove them, so the count functions at the bottom of the script are accurate. Assuming count even counts empty values, in which case this whole thing is a waste of time and something else is wrong.
using UnityEngine;
using System.Collections.Generic;
public class ArrayHolder : MonoBehaviour {.
GameObject[] gridArray = new GameObject[64];
List
- > listOfShipLists = new List
- >();
void Start ()
{
//adds grid spots to gridArray
gridArray = (GameObject.FindGameObjectsWithTag("GridSpot"));
}
void Update ()
{
foreach(List