using UnityEngine;
using System.Collections;
using System;

[Serializable]
public class TextEntry
{
    public GameObject text;
    public float duration;

    public string[] buttons;
};

public class TextController : MonoBehaviour 
{
    public string scene = "";

    public TextEntry[] entries;

    int _Index;
    float _ElapsedTime;

    void Start()
    {
        _Index = 0;
        _ElapsedTime = 0f;

        if (entries.Length > 0)
        {
            entries[0].text.SetActive(true);
        }
    }

    void Update()
    {
        _ElapsedTime += Time.deltaTime;

        if (_Index < entries.Length)
        {
            if (entries[_Index].duration > 0f)
            {
                if (_ElapsedTime >= entries[_Index].duration)
                {
                    entries[_Index].text.SetActive(false);
                    ++_Index;
                    entries[_Index].text.SetActive(true);
                    _ElapsedTime = 0f;
                }
            }
            else
            {
                foreach (string s in entries[_Index].buttons)
                {
                    if (Input.GetButton(s))
                    {
                        ++_Index;
                        _ElapsedTime = 0f;

                        break;
                    }
                }
            }
        }
        else
        {
            if (scene != "")
            {
                Application.LoadLevel(scene);
            }
        }
    }
}
