void HandleBuilding() { if (ownAISettings.delayBeforeStartCreateBuildings > 0 || !selfCommandCenter) { return; } for (int i = 0; i < aiSettings.buildingPriority.Length; i++) { var currentBuilding = aiSettings.buildingPriority[i]; if (currentBuilding == null) { continue; } if (!selfCommandCenter.IsUnitOfTypeInQueue(currentBuilding) && finishedBuildings.Find(unit => unit.data == currentBuilding) == null) { selfCommandCenter.AddUnitToQueue(currentBuilding); break; } } if (selfCommandCenter.unitsQueue.Count > 0 && selfCommandCenter.IsBuildingReady()) { var commandCenterPosition = selfCommandCenter.transform.position; var randomedOffset = new Vector3(Random.Range(-20, 20), 0, Random.Range(-20, 20)); var finalPoint = commandCenterPosition + randomedOffset; var currentBuilding = selfCommandCenter.unitsQueue[0]; var buildingSize = Build.GetBuildingSize(currentBuilding); var buildingRotation = Quaternion.Euler(0, 180, 0); var canBuild = Build.CheckZoneToBuild(finalPoint, buildingSize, buildingRotation, selfPlayerId); if (canBuild) { var spawnedBuildingObject = Build.CreateBuilding(currentBuilding.selfPrefab, finalPoint, buildingRotation, selfPlayerId); var spawnedBuildingUnit = spawnedBuildingObject.GetComponent <Unit>(); finishedBuildings.Add(spawnedBuildingUnit); selfCommandCenter.RemoveUnitFromQueue(currentBuilding, false); } } }