Skip to content
Snippets Groups Projects
Dialog.cs 4.09 KiB
Newer Older
/*
 *      Script par Tanguy Gimenez      
 *
 */

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

public class Dialog : MonoBehaviour
{

    // singleton
    public static Dialog instance;

GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    private void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("Il y a + d'une instance de PlayerNature");
            return;
        }

        instance = this;
    }



    public GameObject dialogBox;
    public Text dialogText;
    public Text instructionText;
    public int dialog;
    public bool dialogActive;
    public string situation;


    // clé : nom de la scène
    // valeur : tableau de string contenant chaque réplique
    private Dictionary<string, string[]> ListDialogs = new Dictionary<string, string[]>();

    // Start is called before the first frame update
    void Start()
    {
        this.dialog = 0;

        string[] DialogsLvl1 = {
             "Ach... Encore eine gute chournée dans mon fillage!",
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
                "Ch'ai très enfie te me balader",
Raffael Di Pietro's avatar
Raffael Di Pietro committed
                "Che defrai aller au Nord dans la forêt ja !",
                "pour me déplacer, je dois utiliser mes  muscles 'flèches directionnelles'"
        this.ListDialogs.Add("start", DialogsLvl1);


        string[] boutiqueChaussure = {
            "Je fous prendrais zes chauzzures en taille Zweiundvierzig Bitte !",
        };
        this.ListDialogs.Add("boutiqueChaussure", boutiqueChaussure);

        string[] boutiqueBaton = {
            "Ze bâton me semble assez long et solide pour moi ! J'achète !",
        };
        this.ListDialogs.Add("boutiqueBaton", boutiqueBaton);

        string[] boutiqueRechaud = {
            " Ze réchaud fa être SEHR PRAKTISCH !", "j'achète tout de zuite !"
        this.ListDialogs.Add("boutiqueRechaud", boutiqueRechaud);

        string[] boutiqueTente = {
            "J'adore ta tente, mais elle est un peu grosse non ?", "Ach, tant pis, CH'ACHETE !"
        };
        this.ListDialogs.Add("boutiqueTente", boutiqueTente);


Raffael Di Pietro's avatar
Raffael Di Pietro committed

        string[] borderChaussure = {
            "NEIN NEIN NEIN ! Il fa me falloir des chaussures pour marcher plus loin !"
Raffael Di Pietro's avatar
Raffael Di Pietro committed
        };
        this.ListDialogs.Add("borderChaussure", borderChaussure);

        string[] borderBaton = {
            "ACH SCHEISSE !", "Ch'ai ouplié mes patons te marches ! Che suis trop fatigué !"
        };
        this.ListDialogs.Add("borderBaton", borderBaton);

        string[] borderRechaud = {
            "Kopfertami, je commence à afoir faim !", "il me faudrait eine réchaud pour mancher !"
        };
        this.ListDialogs.Add("borderRechaud", borderRechaud);

        string[] borderTente = {
            "Hopla, c'est bientôt l'heure de la sièste !", "Si che n'ai pas de tente che ne pourrait pas continuer !"
        };
        this.ListDialogs.Add("borderTente", borderTente);
        if (this.dialogActive)
Raffael Di Pietro's avatar
Raffael Di Pietro committed
            this.setSituation("start");
    }

    // Update is called once per frame
    void Update()
    {
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("joystick button 0")) && dialogActive)
            this.Next();

GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
        if (this.dialogActive)
            this.dialogBox.GetComponent<CanvasRenderer>().SetAlpha(1f);
            this.dialogText.GetComponent<CanvasRenderer>().SetAlpha(1f);
            this.instructionText.GetComponent<CanvasRenderer>().SetAlpha(1f);
            this.dialogBox.GetComponent<CanvasRenderer>().SetAlpha(0f);
            this.dialogText.GetComponent<CanvasRenderer>().SetAlpha(0f);
            this.instructionText.GetComponent<CanvasRenderer>().SetAlpha(0f);
        if (this.dialog >= this.ListDialogs[this.situation].Length)
            this.dialogActive = false;
        else
        {
            this.dialogText.text = this.ListDialogs[this.situation][this.dialog];
            this.dialog++;
        }
    }
Raffael Di Pietro's avatar
Raffael Di Pietro committed
    public void setSituation(string sit)
    {
        this.situation = sit;
        this.dialog = 0;

        this.dialogActive = true;

        this.Next();
    }