using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MessageDisplay : MonoBehaviour {

	public Sprite []scientist;
	public Sprite []pirate;

	public Image messagePic;

	public Text pressSpace;

	public AudioSource messageSound;

	private string dispCharName;

	private float waitTimer;

	public Text messageText;
	// Use this for initialization
	void Start () {
		gameObject.SetActive(false);
	}
	
	public void SetDisplayChar(string charName)
	{
		dispCharName = charName;
	}

	public void ShowMessage(string message, int expression)
	{
		pressSpace.enabled = false;
		if (dispCharName == "pirate")
		{
			messagePic.sprite = pirate[expression];
		}
		else
		{
			messagePic.sprite = scientist[expression];
		}

		gameObject.SetActive(true);
		messageText.text = message;

		waitTimer = 1.0f;
		messageSound.Play();
	}
	// Update is called once per frame
	void Update () {

		if (waitTimer > 0)
			{
				waitTimer -= Time.deltaTime;
				return;
			}
		pressSpace.enabled = true;

		if (Input.GetKeyDown(KeyCode.Space))
		{
			Gameplay gameplay = gameObject.GetComponentInParent<Gameplay>();
			gameplay.togglePause();
			gameObject.SetActive(false);
		}
	}
}
