private void Awake() { battleMenuManager = GameObject.Find("BattleMenuManager").GetComponent <BattleMenuManager>(); infoCanvas = GameObject.Find("infoCanvas").GetComponent <Canvas>(); unitActionCanvas = GameObject.Find("unitActionCanvas").GetComponent <Canvas>(); unitGenerationCanvas = GameObject.Find("unitGenerationCanvas").GetComponent <Canvas>(); mainMenuCanvas = GameObject.Find("mainMenuCanvas").GetComponent <Canvas>(); damageCanvas = GameObject.Find("damageCanvas").GetComponent <Canvas>(); victoryCanvas = GameObject.Find("victoryCanvas").GetComponent <Canvas>(); infoPanel = GameObject.Find("infoPanel").GetComponent <RectTransform>(); victoryPanel = GameObject.Find("victoryPanel").GetComponent <RectTransform>(); moveButton = GameObject.Find("moveButton").GetComponent <Button>(); attackButton = GameObject.Find("attackButton").GetComponent <Button>(); terrainTilemap = GameObject.Find("terrainTilemap").GetComponent <Tilemap>(); secondTilemap = GameObject.Find("secondTilemap").GetComponent <Tilemap>(); upperTilemap = GameObject.Find("upperTilemap").GetComponent <Tilemap>(); cameraPosition = GameObject.Find("Main Camera").transform; newTurnText = GameObject.Find("newTurnText").GetComponent <Text>(); musicSource = GetComponents <AudioSource>()[0]; soundSource = GetComponents <AudioSource>()[1]; ai = gameObject.AddComponent <AI>(); unitActionCanvas.enabled = false; unitGenerationCanvas.enabled = false; mainMenuCanvas.enabled = false; victoryCanvas.enabled = false; if (muted) { musicSource.mute = true; soundSource.mute = true; } }
void createUnitGenerationMenu() { int nUnitTypes = activePlayer.unit.Length; GameObject[] buttons = new GameObject[nUnitTypes]; GameObject[] descriptions = new GameObject[nUnitTypes]; float xPosition = -300f; float yPosition = -20f; BattleMenuManager battleMenuManager = GameObject.Find("BattleMenuManager").GetComponent <BattleMenuManager>(); Transform unitGenerationPanel = unitGenerationCanvas.transform.GetChild(0); for (int i = 0; i < nUnitTypes; i++) { // Create buttons buttons[i] = Instantiate(unitGenerationButton, Vector3.zero, Quaternion.identity); buttons[i].transform.SetParent(unitGenerationPanel); // Set as child of unitGenerationPanel buttons[i].transform.name = "generationButton" + i; buttons[i].transform.localScale = Vector3.one; // Scale to x1 buttons[i].transform.localPosition = new Vector3(xPosition, 100f); buttons[i].transform.localPosition += Vector3.down * yPosition; buttons[i].GetComponent <Button>().onClick.AddListener(battleMenuManager.create); buttons[i].GetComponent <Button>().interactable = false; // Create unit descriptions descriptions[i] = Instantiate(unitGenerationText, Vector3.zero, Quaternion.identity); descriptions[i].transform.SetParent(unitGenerationPanel); // Set as child of unitGenerationPanel descriptions[i].transform.name = "generationText" + i; descriptions[i].transform.localScale = Vector3.one; // Scale to x1 descriptions[i].transform.localPosition = new Vector3(xPosition + 150f, 100f); descriptions[i].transform.localPosition += Vector3.down * yPosition; descriptions[i].GetComponent <Text>().text = Unit.baseUnitName[i] + " (" + Unit.baseCost[i] + ")\n" + "Health: " + Unit.baseHealth[i] + "\tPower: " + Unit.basePower[i] + "\n" + "Move: " + Unit.baseMovementRange[i] + "\tRange: " + Unit.baseRange[i]; yPosition += 65f; if (i == 4) // Prepare for second column { xPosition += 350f; yPosition = -20f; } } }
public void enableAllUnitGenerationButtons() { Transform unitGenerationPanel = unitGenerationCanvas.transform.GetChild(0).transform; foreach (Button b in unitGenerationPanel.GetComponentsInChildren <Button>()) { if (b.name == "Cancel") { b.interactable = true; continue; } // Find cost of the unit int buttonNumber = BattleMenuManager.getButtonNumber(b.name); int neededMoney = Unit.baseCost[buttonNumber]; // Only allow interaction with a button if that player has enough money to buy the unit if (activePlayer.money >= neededMoney) { b.interactable = true; } } }
private void Awake() { cursor = GetComponentInParent <Cursor>(); battleMenuManager = GameObject.Find("BattleMenuManager").GetComponent <BattleMenuManager>(); }