Skip to content
Snippets Groups Projects
Portrait.cs 1.62 KiB
Newer Older
Michael LaFreniere's avatar
Michael LaFreniere committed
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

// ** Can potentially merge with the money script.

Michael LaFreniere's avatar
Michael LaFreniere committed
// script to change the top left player portrait based on the player appearance and toggle the inventory panel.
Michael LaFreniere's avatar
Michael LaFreniere committed
public class Portrait : MonoBehaviour {

    private setAppearance appearance;
Michael LaFreniere's avatar
Michael LaFreniere committed
    private PlayerStats stats; // to access name
Michael LaFreniere's avatar
Michael LaFreniere committed
    public Text playerName;
    public Image face;
    public Image head;
Michael LaFreniere's avatar
Michael LaFreniere committed
    private Color color;
    private CanvasGroup inventory; // to toggle the panel on and off
Michael LaFreniere's avatar
Michael LaFreniere committed

	// Use this for initialization
	void Start () {
Michael LaFreniere's avatar
Michael LaFreniere committed
        stats = GameObject.Find("Player").GetComponent<PlayerStats>();
        appearance = GameObject.Find("Player").GetComponent<setAppearance>();
Michael LaFreniere's avatar
Michael LaFreniere committed
        inventory = GameObject.Find("inventoryPanel").GetComponent<CanvasGroup>();
Michael LaFreniere's avatar
Michael LaFreniere committed
        color = appearance.getColor();
        playerName.text = stats.getName();
        face.sprite = appearance.getFace();
        head.sprite = appearance.getHead();
        face.color = color;
        head.color = color;
Michael LaFreniere's avatar
Michael LaFreniere committed
        // inventory initially invisible
        inventory.alpha = 0;
        inventory.interactable = false;
        inventory.blocksRaycasts = false;
Michael LaFreniere's avatar
Michael LaFreniere committed
    }
	
Michael LaFreniere's avatar
Michael LaFreniere committed
	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;
        }
    }
Michael LaFreniere's avatar
Michael LaFreniere committed
}