Newer
Older
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;
public Text playerName;
public Image face;
public Image head;
private CanvasGroup inventory; // to toggle the panel on and off
private GameObject[] buttons; // to turn + buttons on/off
// 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;
stats = GameObject.Find("Player").GetComponent<PlayerStats>();
appearance = GameObject.Find("Player").GetComponent<setAppearance>();
inventory = GameObject.Find("inventoryPanel").GetComponent<CanvasGroup>();
buttons = GameObject.FindGameObjectsWithTag("incrementStat");
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;
void Update() {
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();
// 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
}
}
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
inventory.alpha = 1; // show
inventory.interactable = true;
inventory.blocksRaycasts = true;
}
}