How do I Scene Switch after Dialogue is finished,How do I change Scene after the Dialogue is finished?
So I was doing a 3D platformer with some Dialogue sometimes when you start or finish a Level. So I need to Change Scene to the next Level after the Dialogue. So here I got the Dialogue Trigger, that is set to an Invisible Box and in another Script, triggers with an OnCollisionEnter when the Player hits the Box Collider. I might just be dumb and you can't Array a Bool, but the IDE would have told me right? Please help!
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
{
public Message[] messages;
public Actor[] actors;
public Changescene[] change;
public void StartDialogue()
{
FindObjectOfType<DialogueManager>().OpenDialogue(messages, actors, change);
}
}
[System.Serializable]
public class Message
{
public int actorID;
[TextArea(3, 10)]
public string message;
}
[System.Serializable]
public class Actor
{
public string name;
public Sprite sprite;
}
[System.Serializable]
public class Changescene
{
public bool change;
public string levelName;
}
And here is the Manager if the Dialogue itself, and what is giving me the trouble. I have a Textbox with Name of the Character, a Sprite or small Pic of him, and the Text itself. The Idea is to in the Trigger, put if you want to Change Scene After, and write the Name of the new one down. And that works, but I can't figure out what is wrong with me calling upon the changed stuff.
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Image = UnityEngine.UI.Image;
public class DialogueManager : MonoBehaviour
{
public Image actorImage;
public Text actorName;
public Text messageText;
public RectTransform backgroundBox;
private Message[] _currentMessages;
private Actor[] _currentActors;
private int _activeMessages;
private static bool _isActive;
private Changescene[] _changescenes;
public void OpenDialogue(Message[] messages, Actor[] actors, Changescene[] changescenes)
{
_currentMessages = messages;
_currentActors = actors;
_activeMessages = 0;
_isActive = true;
_changescenes = changescenes;
Debug.Log("Dialogue started, there are messages: " + messages.Length);
DisplayMessage();
backgroundBox.LeanScale(Vector3.one, 0.5f).setEaseInOutExpo();
}
private void DisplayMessage()
{
Message messageToDisplay = _currentMessages[_activeMessages];
messageText.text = messageToDisplay.message;
Actor actorToDisplay = _currentActors[messageToDisplay.actorID];
actorName.text = actorToDisplay.name;
actorImage.sprite = actorToDisplay.sprite;
}
private void NextMessage()
{
_activeMessages++;
if (_activeMessages < _currentMessages.Length)
{
DisplayMessage();
} else {
Debug.Log("Dialogue Finished");
_isActive = false;
Changescene checkswitch = _changescenes.change;
Changescene sceneChangedToo = _changescenes.levelName;
if (checkswitch == true)
{
SceneManager.LoadScene(sceneChangedToo);
}
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) && _isActive)
{
NextMessage();
}
}
}