void Start() { groundCount = 0; WorldData data = SaveLogic.LoadWorld(); saveExists = data.savedGame; mouseRotatorScript.enabled = false; GroundBuild(); HighwayBuild(); }
public void LoadWorld() { WorldData data = SaveLogic.LoadWorld(); worldScript.objects = data.objects; worldScript.Xpositions = data.Xpositions; worldScript.Ypositions = data.Ypositions; worldScript.Zpositions = data.Zpositions; goldScript.gold = data.gold; populationScript.population = data.population; populationScript.residentHappiness = data.residenthappiness; placementScript.houses = data.houses; worldScript.residents = data.residents; existingHouses = GameObject.FindGameObjectsWithTag("Build"); for (int i = 0; i < existingHouses.Length; i++) { Destroy(existingHouses[i]); } existingRoads = GameObject.FindGameObjectsWithTag("Road"); for (int i = 0; i < existingRoads.Length; i++) { Destroy(existingRoads[i]); } existingTerrain = GameObject.FindGameObjectsWithTag("Terrain"); for (int i = 0; i < existingHouses.Length; i++) { Destroy(existingTerrain[i]); } for (int i = 0; i < worldScript.objects.Length; i++) { if (data.objects[i] == "House1") { prefab = House1; houseCapacity = 5; } else if (data.objects[i] == "House2") { prefab = House2; houseCapacity = 8; } else if (data.objects[i] == "tree") { prefab = tree; } else if (data.objects[i] == "tree1") { prefab = tree1; } else if (data.objects[i] == "tree2") { prefab = tree2; } else if (data.objects[i] == "road") { prefab = road; } else if (data.objects[i] == "cornerRoad") { prefab = cornerRoad; } else if (data.objects[i] == "cornerRoadLeftBottom") { prefab = cornerRoadLeftBottom; } else if (data.objects[i] == "cornerRoadRightTop") { prefab = cornerRoadRightTop; } else if (data.objects[i] == "cornerRoadRightBottom") { prefab = cornerRoadRightBottom; } else if (data.objects[i] == "3wayRoad") { prefab = threeWayRoad; } else if (data.objects[i] == "3wayRoadLeft") { prefab = threeWayRoadLeft; } else if (data.objects[i] == "3wayRoadUpwards") { prefab = threeWayRoadUpwards; } else if (data.objects[i] == "3wayRoadDown") { prefab = threeWayRoadDown; } else if (data.objects[i] == "4cornerRoad") { prefab = fourCornerRoad; } else if (data.objects[i] == "roadVertical") { prefab = roadVertical; } else { prefab = null; } if (prefab != null) { currentObject = Instantiate(prefab); currentObject.transform.SetPositionAndRotation(new Vector3(data.Xpositions[i], data.Ypositions[i], data.Zpositions[i]), currentObject.transform.rotation); if (prefab == House1 || prefab == House2) { HouseLogic houseScript = currentObject.GetComponent <HouseLogic>(); houseScript.capacity = houseCapacity; houseScript.houseNumber = i; } if (prefab.tag == "Road") { currentObject.name = "Road" + i; } if (currentObject.tag == "Terrain") { currentObject.name = "Tree" + i; } } } }