An error occurred while loading the file. Please try again.
-
GIMENEZ TANGUY authored9a23d283
Dialog.cs 4.68 KiB
/*
* 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;
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[] DialogsStart = {
"Ach... Encore ein gute chournée dans mon fillage!",
"Ch'ai très enfie te me balader",
"Che defrai aller au Nord dans la forêt ja !"
};
this.ListDialogs.Add("start", DialogsStart);
string[] Dialogsraff = {
"Salut",
"cava ?",
"Je te mange tes morts"
};
this.ListDialogs.Add("pnj", Dialogsraff);
string[] DialogsTest = {
"Je fais un test",
"ca marche ? ou pas ?",
"bisous"
};
this.ListDialogs.Add("test", DialogsTest);
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);
string[] borderChaussure = {
"NEIN NEIN NEIN ! Il fa me falloir des chaussures pour marcher plus loin !"
};
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)
this.setSituation("start");
}
// Update is called once per frame
void Update()
{
if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("joystick button 0")) && dialogActive)
this.Next();
// // DEBUG
// if ((Input.GetKeyDown(KeyCode.H) || Input.GetKeyDown("joystick button 1")))
// this.dialogActive = !this.dialogActive;
// // DEBUG
// if (Input.GetKeyDown(KeyCode.F))
// {
// Debug.Log("tut");
// this.setSituation("marchand");
// }
if (this.dialogActive)
{
this.dialogBox.GetComponent<CanvasRenderer>().SetAlpha(1f);
this.dialogText.GetComponent<CanvasRenderer>().SetAlpha(1f);
this.instructionText.GetComponent<CanvasRenderer>().SetAlpha(1f);
}
else
{
this.dialogBox.GetComponent<CanvasRenderer>().SetAlpha(0f);
this.dialogText.GetComponent<CanvasRenderer>().SetAlpha(0f);
this.instructionText.GetComponent<CanvasRenderer>().SetAlpha(0f);
}
}
void Next()
{
if (this.dialog >= this.ListDialogs[this.situation].Length)
this.dialogActive = false;
else
{
this.dialogText.text = this.ListDialogs[this.situation][this.dialog];
this.dialog++;
}
}
public void setSituation(string sit)
{
this.situation = sit;
this.dialog = 0;
this.dialogActive = true;
this.Next();
}
}