Skip to content
Snippets Groups Projects
TutorialMessageController.cs 1.52 KiB
Newer Older
Moritz Meyerhof's avatar
Moritz Meyerhof committed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

struct TutorialObject
{
    public TutorialObject(string message, Vector2 vector2)
    {
        tutorialMessage = message;
        messagePosition = vector2;
    }

    public string tutorialMessage;
    public Vector2 messagePosition;
}
Moritz Meyerhof's avatar
Moritz Meyerhof committed

public class TutorialMessageController : MonoBehaviour
{
    [SerializeField] List<string> keyTut;
    [SerializeField] List<string> messagesTut;
    [SerializeField] List<Vector2> posMessages;

    [SerializeField] GameObject textPrefab;
    GameObject activeMessage = null;
    Dictionary<string, TutorialObject> messages = new Dictionary<string, TutorialObject>();

    GameObject canvas;

    private void Awake()
Moritz Meyerhof's avatar
Moritz Meyerhof committed
    {
        canvas = GetComponent<Canvas>().gameObject;

        //create Dict with Structs
        for (int i = 0; i < keyTut.Count; i++)
        {
            messages.Add(keyTut[i],new TutorialObject(messagesTut[i],posMessages[i]));
        }
Moritz Meyerhof's avatar
Moritz Meyerhof committed
    }

    public void ActivateTutorial(string tutorialType)
Moritz Meyerhof's avatar
Moritz Meyerhof committed
    {
        if ( activeMessage != null)
        {
            Destroy(activeMessage);
        }
        if ( tutorialType == "return")
        {
            SceneLoader.instance.LoadScene("Forest");
            return;
        }
        TutorialObject activePair = messages[tutorialType];
        GameObject temp = Instantiate(textPrefab,activePair.messagePosition,Quaternion.identity, canvas.transform);
        temp.GetComponent<Text>().text = activePair.tutorialMessage;
Moritz Meyerhof's avatar
Moritz Meyerhof committed
    }
Moritz Meyerhof's avatar
Moritz Meyerhof committed
}