void OnMouseDown() { CreateManager createManager = GameObject.FindGameObjectWithTag("createManager").transform.GetComponent <CreateManager> (); bool creating = createManager.creating; if (creating) { if (this.GridType == 1) { createManager.creating = false; return; } Transform newTransform = createManager.newTransform; Quaternion rotation = createManager.rotation; int maxOutput = createManager.maxOutput; int directionIndex = createManager.directionIndex; int cost = createManager.cost; Vector3 pos = transform.position; pos.y += 1; Transform newObject = (Transform)Instantiate(newTransform, pos, rotation); TurbineInfo newTurbineInfo = newObject.GetComponent <TurbineInfo> (); newTurbineInfo.maxOutput = maxOutput; newTurbineInfo.CalculateOutput(Elevation); newTurbineInfo.directionIndex = directionIndex % 8; newTurbineInfo.cost = cost; MoneyManager.money -= cost + ExtraCost; createManager.turbineNum++; createManager.creating = false; } if (!creating) { GameObject.FindGameObjectWithTag("screens").GetComponent <CustomizationSwitch> ().toSelectionP(); GameObject.FindGameObjectWithTag("selectionPanel").GetComponent <InfoPanel> ().UpdateInfo(gameObject.transform.GetComponent <GridInfo>()); Debug.Log(GetInfo()); GameObject.FindGameObjectWithTag("createManager").transform.position = gameObject.transform.position; } }
public void proposeRepairTurbine(Transform newObject) { repairObject = newObject; repairObjectInfo = newObject.GetComponent <TurbineInfo> (); }
public void proposeRepairTurbine(Transform newObject) { repairObject = newObject; repairObjectInfo = newObject.GetComponent<TurbineInfo> (); }
// Use this for initialization void Start() { myTurbineInfo = transform.parent.parent.GetComponent<TurbineInfo> (); }
public void loadMap() { for (int x = 0; x < 20; x++) { for (int z = 0; z < 20; z++) { gridInfo[x, z] = 0; placeItemInfo[x, z] = 0; } } Vector2 prev = gridTurningPoints[0]; for (int i = 1; i < gridTurningPoints.Count; i++) { loadRoute(prev, gridTurningPoints[i]); prev = gridTurningPoints[i]; } //Detect the palce of all turbines, pumps and transformers that already in the scene GameObject[] allTurbines = GameObject.FindGameObjectsWithTag("turbine"); GameObject[] allPumps = GameObject.FindGameObjectsWithTag("waterTower"); GameObject[] allTransformers = GameObject.FindGameObjectsWithTag("transformer"); GameObject[] allTransformerForTurbines = GameObject.FindGameObjectsWithTag("transformerForTurbine"); for (int i = 0; i < allTurbines.Length; i++) { Transform currentTransform = allTurbines[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TurbineInfo currentTurbine = allTurbines[i].transform.GetComponent <TurbineInfo>(); currentTurbine.x = (int)gridPlace.x; currentTurbine.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allPumps.Length; i++) { Transform currentTransform = allPumps[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); PumpInfo currentPump = allPumps[i].transform.GetComponent <PumpInfo>(); currentPump.x = (int)gridPlace.x; currentPump.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allTransformers.Length; i++) { Transform currentTransform = allTransformers[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TransformerInfo currentTransformer = allTransformers[i].transform.GetComponent <TransformerInfo>(); currentTransformer.x = (int)gridPlace.x; currentTransformer.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allTransformerForTurbines.Length; i++) { Transform currentTransform = allTransformerForTurbines[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TransformerForTurbineInfo currentTransformerForTurbine = allTransformerForTurbines[i].transform.GetComponent <TransformerForTurbineInfo>(); currentTransformerForTurbine.x = (int)gridPlace.x; currentTransformerForTurbine.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } }
void OnMouseDown() { if (LockUI.OverGui) { return; } //sellButton.GetComponent<SellManager>().disableButton(); GameObject sellBtn = GameObject.FindGameObjectWithTag("sellButton"); GameObject repairBtn = GameObject.FindGameObjectWithTag("repairButton"); if (sellBtn != null) { sellBtn.GetComponent <SellManager> ().disableButton(); } if (repairBtn != null) { repairBtn.GetComponent <RepairManager> ().disableButton(); } AudioSource.PlayClipAtPoint(click, Camera.main.transform.position, 0.8f); CreateManager createManager = GameObject.FindGameObjectWithTag("createManager").transform.GetComponent <CreateManager> (); bool creating = createManager.creating; CreateManager.createType createType = createManager.currentType; if (creating) { if (this.GridType == 1 || TerrainInfo.placeItemInfo[x, z] == 1) { createManager.creating = false; return; } if (createType == CreateManager.createType.turbine) { Transform newTransform = createManager.newTransform; Quaternion rotation = createManager.rotation; int maxOutput = createManager.maxOutput; int directionIndex = createManager.directionIndex; int cost = createManager.cost; float timeForWork = createManager.timeForWork; Vector3 pos = transform.position; pos.y += 1; Transform newObject = (Transform)Instantiate(newTransform, pos, rotation); TurbineInfo newTurbineInfo = newObject.GetComponent <TurbineInfo> (); newTurbineInfo.maxOutput = maxOutput; newTurbineInfo.CalculateOutput(Elevation); newTurbineInfo.directionIndex = directionIndex % 8; newTurbineInfo.cost = cost; newTurbineInfo.timeForWork = timeForWork; newTurbineInfo.turbineColor = createManager.turbineColor; Debug.Log(timeForWork); newTurbineInfo.x = x; newTurbineInfo.z = z; if (MoneyManager.money < cost + ExtraCost) { createManager.finishCreateTurbine(); Destroy(newObject.gameObject); } else { MoneyManager.money -= cost + ExtraCost; CreateManager.turbineNum++; createManager.finishCreateTurbine(); TerrainInfo.placeItemInfo[x, z] = 1; } } //Create Pump here else if (createType == CreateManager.createType.pump) { } //Create Transformer here else if (createType == CreateManager.createType.transformer) { } } if (!creating) { GameObject.FindGameObjectWithTag("screens").GetComponent <CustomizationSwitch> ().toSelectionP(); GameObject.FindGameObjectWithTag("selectionPanel").GetComponent <InfoPanel> ().UpdateInfo(gameObject.transform.GetComponent <GridInfo>()); Debug.Log(GetInfo()); GameObject.FindGameObjectWithTag("createManager").transform.position = gameObject.transform.position; } }
// Use this for initialization void Start() { myTurbineInfo = transform.parent.parent.GetComponent <TurbineInfo> (); }