Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7.  
  8. public class GameManager : MonoBehaviour
  9. {
  10.  
  11.     public GameObject DialogueObject;
  12.     public TextMeshProUGUI characterNameText;
  13.     public TextMeshProUGUI dialogText;
  14.     public System.Action dialogOnFinishAction;
  15.     int number = 10;
  16.  
  17.     private void Awake()
  18.     {
  19.         ShowDialog("potato", "what is your number?", () => { ShowDialog("potato", "Your number is " + number, null); });
  20.     }
  21.  
  22.     public void ShowDialog(string CharacterName, string Text, System.Action onFinish)
  23.     {
  24.  
  25.         characterNameText.text = CharacterName;
  26.         dialogText.text = Text;
  27.         onFinish = dialogOnFinishAction;
  28.  
  29.         DialogueObject.SetActive(true);
  30.     }
  31.  
  32.     // Start is called before the first frame update
  33.     void Start()
  34.     {
  35.         DialogueObject.SetActive(false);
  36.     }
  37.  
  38.     // Update is called once per frame
  39.     void Update()
  40.     {
  41.         if ((Input.GetKeyDown(KeyCode.Return)))
  42.         {
  43.             if (dialogOnFinishAction != null)
  44.             {
  45.                 System.Action action = dialogOnFinishAction;
  46.                 dialogOnFinishAction = null;
  47.                 action();
  48.             }
  49.             else
  50.             {
  51.                 DialogueObject.SetActive(false);
  52.             }
  53.         }
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement