I know i can call the IEnumerator as a coroutine only in a class inherited from monobehaviour and in a non static method or make a instance of this class in. It gives me a lot of problems since i’ve wanted to check if there is a free space in a given coodinates in my voxel enginge app. I thought about threading, it would solve my problem, but I heard unity doesn’t support this kind of way. So the main problem is:
I try to do this:
public IEnumerator CoBuilding()
{
foreach (Vector3 block in blocks)
{
foreach (Building building in Player.buildings)
{
foreach (Vector3 alreadyset in building.blocks)
{
if (block == alreadyset)
{
yield break;
}
yield return null;
}
}
}
Build ();
yield return null;
}
Its a method called in the constructor of class Building, after setting blocks coords. Its looking if there is any building, in the given coords when the new building has to be placed. If there is, its breaking and not build the construction. The problem is - when I make it a bool function it works, but as i have more buildings in my game it processing more time(0.1s - 1.5 s), i want to do yield inside, after 1 loop done to not freeze the game. How can i call it in a non monobehaviour class? My buildings are placed in a mesh, i dont want to create any gameobjects.