Exemplo n.º 1
0
 public void InstantiateBuilding(BuildableStructure building)
 {
     cancelBuilding();               // TODO: bug: sometimes building gets placed before InstantiateBuilding() and therefore cancelBuilding is called
     currentbuilding = Instantiate(building.gameObject, Vector3.zero, Quaternion.identity);
     currentbuilding.GetComponent <BuildableStructure>().setWarningManager(warningmanager);
     resourcemanager.setProjectCosts(buildcosts[currentbuilding.GetComponent <BuildableStructure>().getBuildingType()]);
 }
Exemplo n.º 2
0
    void Update()
    {
        if (currentbuilding != null)        // while placing building
        {
            BuildableStructure currentBuildableStructure = currentbuilding.GetComponent <BuildableStructure>();
            if (currentBuildableStructure.hasPlaced())            // if building placed
            {
                if (resourcemanager.subtractResources(buildcosts[currentBuildableStructure.getBuildingType()]))
                {
                    addStructure(currentbuilding);
                    resourcemanager.unsetProjectCosts();

                    if (currentBuildableStructure.getBuildingType() == BuildableStructure.Buildingtype.spaceport)
                    {
                        launch.gameObject.SetActive(true);
                    }

                    currentbuilding = null;
                }
                else
                {
                    cancelBuilding();
                    warningmanager.setWarning("Not enough resources");
                }
            }
            if (currentbuilding != null && Input.GetKeyDown(KeyCode.R))
            {
                Vector3 currentRotation = currentbuilding.transform.rotation.eulerAngles;
                currentbuilding.transform.rotation = Quaternion.Euler(currentRotation + new Vector3(0, 90, 0));
            }
            if (Input.GetMouseButtonDown(1))            // if building cancelled
            {
                cancelBuilding();
            }
        }
    }