Example #1
0
    IEnumerator BuildBuilding(Building building)
    {
        isBuilding = true;
        buildBar.transform.position = building.gameObject.transform.position - new Vector3(building.info.anchorOffset.x, 0, building.info.anchorOffset.y);
        buildBar.gameObject.SetActive(true);
        barUI.transform.localScale = new Vector3(0, 1, 1);

        float endTime = Time.time + buildTime;

        while (isBuilding && (Time.time < endTime))
        {
            float timeLeft = endTime - Time.time;
            barUI.transform.localScale = new Vector3(1 - (timeLeft / buildTime), 1, 1);
            yield return(null);
        }

        if (isBuilding)
        {
            if (building.state == Building.BuildingState.Blueprint)
            {
                blueprints.Remove(ResourcePickup.GetAtPosition(building.coveredTiles [0]));
                tm.BuildBuilding(building);
            }
            else if (building.state == Building.BuildingState.Inactive)
            {
                tm.BreakDownBuilding(building);
            }
        }

        isBuilding = false;
        buildBar.gameObject.SetActive(false);
        SavedGame.UpdateBuildings();
    }