private void BuildBuilding(BaseObject target) { AICamp camp = GameObject.Find("AIHandler").GetComponent <AICamp>(); Vector3 campLocation = camp.GetCampLocation(); float campRadius = camp.GetCampRadius(); Vector3 possibleBuildingPlacement = GetRandomPositionInsideCamp(campLocation, campRadius); BaseBuilding newObject = Instantiate <BaseObject>(target, possibleBuildingPlacement, Quaternion.Euler(Vector3.zero)) as BaseBuilding; //Try to place object around camp max 10 times. for (int i = 0; i < 10 && BuildingPlacer.HitsObstacle(possibleBuildingPlacement, newObject.transform); i++) { possibleBuildingPlacement = GetRandomPositionInsideCamp(campLocation, campRadius); } if (!BuildingPlacer.HitsObstacle(possibleBuildingPlacement, newObject.transform)) { possibleBuildingPlacement.y += newObject.GetComponentInChildren <Collider>().bounds.size.y; //possibleBuildingPlacement.y += newObject.transform.position.y; //Offset the building to be above ground newObject.SetPlayer(player); newObject.AddLifecycleListener(this); newObject.OnCreated(); } else { Debug.LogError("A placement was not found"); newObject.RemoveObject(); } }
public void AddBuilding(BaseBuilding obj) { obj.AddLifecycleListener(this); builtBuildings.Add(obj); }