80 lines
1.9 KiB
C#
80 lines
1.9 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CutsceneManager : MonoBehaviour
|
|
{
|
|
[Header("Status")]
|
|
public DialogueScript scriptToShow;
|
|
public int currentText;
|
|
[Header("UI")]
|
|
public TextMeshProUGUI nameText;
|
|
public TextMeshProUGUI dialogueText;
|
|
public Image sceneImage;
|
|
[Header("Audio")]
|
|
public AudioSource source;
|
|
|
|
private void Start()
|
|
{
|
|
StartCutscene(LevelSwitcher.instance.currentScript);
|
|
}
|
|
|
|
public void StartCutscene(DialogueScript newDialogue)
|
|
{
|
|
currentText = 0;
|
|
scriptToShow = newDialogue;
|
|
if (scriptToShow.musicToPlay)
|
|
{
|
|
source.clip = scriptToShow.musicToPlay;
|
|
source.volume = scriptToShow.volume;
|
|
source.Play();
|
|
}
|
|
SetDialogue();
|
|
}
|
|
|
|
public void ContinueDialogue()
|
|
{
|
|
currentText++;
|
|
if (currentText >= scriptToShow.dialogueList.Length)
|
|
{
|
|
EndDialogue();
|
|
return;
|
|
}
|
|
SetDialogue();
|
|
}
|
|
|
|
private void SetDialogue()
|
|
{
|
|
DialogueScript.Dialogue currentDialogue = scriptToShow.dialogueList[currentText];
|
|
if (currentDialogue.character)
|
|
{
|
|
nameText.text = currentDialogue.character.characterName;
|
|
dialogueText.color = currentDialogue.character.textColor;
|
|
}
|
|
else
|
|
{
|
|
nameText.text = "";
|
|
dialogueText.color = Color.white;
|
|
}
|
|
sceneImage.sprite = currentDialogue.cutsceneImage;
|
|
dialogueText.text = currentDialogue.text;
|
|
}
|
|
|
|
public void EndDialogue()
|
|
{
|
|
LevelSwitcher.instance.SwitchLevel(scriptToShow.nextScene);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
ContinueDialogue();
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
EndDialogue();
|
|
}
|
|
}
|
|
}
|