public void SetupReferences() { mainBattle = GameObject.Find("BattleCode").GetComponent <MainBattle> (); battleManager = mainBattle.manager; battleManager.forceCriticalHits = "None"; player = battleManager.Player; enemy = battleManager.Enemy; buttonManager = GameObject.Find("ButtonHandler").GetComponent <BattleButtons> (); }
void Awake() { Debug.Log("What is going on?"); if (mainBattle == null) { mainBattle = this; } else { Destroy(this); } }
public void SetupReferences() { mainBattle = GameObject.Find("BattleCode").GetComponent <MainBattle> (); battleManager = mainBattle.manager; battleManager.forceCriticalHits = "None"; player = battleManager.Player; enemy = battleManager.Enemy; enemyStats = GameObject.Find("EnemyStats"); playerStats = GameObject.Find("PlayerStats"); enemyHealthBar = enemyStats.transform.Find("Health/Text").GetComponent <Text>(); playerHealthBar = playerStats.transform.Find("Health/Text").GetComponent <Text>(); enemyMagicBar = enemyStats.transform.Find("Magic/Text").GetComponent <Text>(); playerMagicBar = playerStats.transform.Find("Magic/Text").GetComponent <Text>(); }
/// <summary> /// On start, show all existing players and their stats. Also disable back button if entered /// after the current player has just died /// [EXTENSION] - If a player has faded, grey out their cell to make it clearer to see /// </summary> void Start() { players = PlayerData.instance.data.Players; mainBattle = GameObject.Find("BattleCode").GetComponent <MainBattle> (); GameObject cell; GameObject container; GameObject stats; Texture2D image; //Loop through all players for (int i = 0; i < 6; i++) { cell = GameObject.Find("Player" + (i + 1)); container = cell.transform.Find("Container").gameObject; //If player exits if (players [i] != null) { //If player fainted, fade out if (players [i].Health == 0) { container.transform.Find("Backdrop").GetComponent <Image> ().color = Color.grey; } //Setup all sprites and player stats display image = players [i].Image; container.transform.Find("Image").GetComponent <Image>().sprite = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f)); container.transform.Find("Name").GetComponent <Text> ().text = players [i].Name; stats = container.transform.Find("Stats").gameObject; stats.transform.Find("Level").GetComponent <Text> ().text = "Level: " + players [i].Level.ToString(); stats.transform.Find("Health").GetComponent <Text> ().text = "Health: " + players [i].Health.ToString() + " / 100"; stats.transform.Find("Attack").GetComponent <Text> ().text = "Attack: " + players [i].Attack.ToString(); stats.transform.Find("Defence").GetComponent <Text> ().text = "Defence: " + players [i].Defence.ToString(); stats.transform.Find("Magic").GetComponent <Text> ().text = "Magic: " + players [i].Magic.ToString() + " / " + players[i].MaximumMagic.ToString(); stats.transform.Find("Luck").GetComponent <Text> ().text = "Luck: " + players [i].Luck.ToString(); stats.transform.Find("Speed").GetComponent <Text> ().text = "Speed: " + players [i].Speed.ToString(); stats.transform.Find("Exp").GetComponent <Text> ().text = "Exp: " + players [i].Exp.ToString() + " / " + players[i].ExpToNextLevel.ToString(); if (players [i].Health == 0) //if the player has fainted //colour then grey to make it easier to say, and also destroy button component so that they can't be selected { container.GetComponent <Image> ().color = Color.grey; Destroy(cell.GetComponent <Button> ()); } //If player doesn't exists } else { //Destroy all children, leaving the container empty var children = new List <GameObject>(); foreach (Transform child in container.transform) { children.Add(child.gameObject); } children.ForEach(child => Destroy(child)); container.GetComponent <Image> ().color = Color.grey; Destroy(cell.GetComponent <Button> ()); //Remove button component so can't be pressed } } //Disable attack button if opened after player has died if (mainBattle.playerDied) { GameObject.Find("BackButton").GetComponent <Button> ().interactable = false; } }