This code worked fine and everything but it seemed to pause once the trees were staring to get into their 1000's of instances. The navmesh agent would just wait at it's current position and do nothing until a new batch of trees would placed in and then just move to one and pause again. But once I had it terminate the for loop it would continuously move from tree to tree as desired. Why is this? I thought it updated the frame once the OnCollision code was resolved. Is it because there were too many things in the list for it to sort?
Code:
void OnCollisionEnter(Collision collision)
{
GameObject data = GameObject.Find("Data");
List<GameObject> treeLists = data.GetComponent<DataStorage>().treeList;
for (removeArea = 0; treeLists.Count > removeArea; removeArea++)
{
if (treeLists[removeArea] != null)
if (collision.gameObject.name == treeLists[removeArea].name)
{
GameObject.Destroy(collision.gameObject);
treeLists[removeArea] = null;
removeArea = treeLists.Count; //Added this
}
}
}
removeArea was supposed to be for something else which I decided to scrap. It isn't used anywhere else in the code.
Is there any way to make it process the for loop before rendering the next frame?