using UnityEngine; using System.Collections; using UnityEngine.UI; // ** Can potentially merge with the money script. // script to change the top left player portrait based on the player appearance and toggle the inventory panel. public class Portrait : MonoBehaviour { private setAppearance appearance; private PlayerStats stats; // to access name public Text playerName; public Image face; public Image head; private Color characterColor; public Text healthBar; public Image healthBarRed; private CanvasGroup inventory; // to toggle the panel on and off private GameObject[] buttons; // to turn + buttons on/off public CanvasGroup helpText; // the 'CLICK HERE' below portrait // fields used to set the inventory panel information // stats public Text vitality; public Text strength; public Text defense; public Text agility; public Text luck; public Text unallocated; public static int unallocatedStats; // poitions public Text healthPotCount; public Text strengthPotCount; public Text defensePotCount; public Text agilityPotCount; // blessings public Image offenseBlessing; public Image defenseBlessing; public Image luckBlessing; void Start () { stats = GameObject.Find("Player").GetComponent<PlayerStats>(); appearance = GameObject.Find("Player").GetComponent<setAppearance>(); inventory = GameObject.Find("inventoryPanel").GetComponent<CanvasGroup>(); buttons = GameObject.FindGameObjectsWithTag("incrementStat"); healthBarRed = GameObject.Find("healthBarFullp").GetComponent<Image>(); characterColor = appearance.getColor(); playerName.text = stats.getName(); face.sprite = appearance.getFace(); head.sprite = appearance.getHead(); head.color = characterColor; offenseBlessing.color = Color.white; defenseBlessing.color = Color.white; luckBlessing.color = Color.white; setInventory(); // inventory initially invisible inventory.alpha = 0; inventory.interactable = false; inventory.blocksRaycasts = false; helpText.interactable = false; helpText.blocksRaycasts = false; if (ArenaCombatControl.winCount > 0) { helpText.alpha = 0; } } void Update() { if (PlayerStats.curHealth <= 0) { healthBarRed.enabled = false; } else { healthBarRed.enabled = true; } healthBar.text = PlayerStats.curHealth.ToString() + " / " + PlayerStats.maxHealth.ToString(); healthBarRed.fillAmount = (float)PlayerStats.curHealth / PlayerStats.maxHealth; // to make + buttons appear when buying stats if (unallocatedStats > 0) { for (int i = 0; i < buttons.Length; i++) { buttons[i].SetActive(true); } } else { for (int i = 0; i < buttons.Length; i++) { buttons[i].SetActive(false); } } } public void setInventory() { // get stats vitality.text = PlayerStats.vitality.ToString(); strength.text = PlayerStats.strength.ToString(); defense.text = PlayerStats.defense.ToString(); agility.text = PlayerStats.agility.ToString(); luck.text = PlayerStats.luck.ToString(); unallocated.text = unallocatedStats.ToString(); stats.setMaxHealth(); // get potions healthPotCount.text = PlayerStats.healthPotions.ToString(); strengthPotCount.text = PlayerStats.strengthPotions.ToString(); defensePotCount.text = PlayerStats.defensePotions.ToString(); agilityPotCount.text = PlayerStats.agilityPotions.ToString(); // get blessings if (PlayerStats.offenseBlessing == true) { offenseBlessing.color = Color.green; // show the blessing as active } if (PlayerStats.defenseBlessing == true) { defenseBlessing.color = Color.green; // show the blessing as active } if (PlayerStats.luckBlessing == true) { luckBlessing.color = Color.green; // show the blessing as active } } // when clicking the player's portrait public void OnClick() { if (inventory.alpha == 1) { // if the inventory screen is up inventory.alpha = 0; // hide inventory.interactable = false; inventory.blocksRaycasts = false; } else if (inventory.alpha == 0) { // if the inventory screen is hidden setInventory(); inventory.alpha = 1; // show inventory.interactable = true; inventory.blocksRaycasts = true; // remove the helper text (CLICK HERE) helpText.alpha = 0; } } }