Advertisement
AndrewRosyaev

Dialogue

May 11th, 2016
2,918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Dialogue : MonoBehaviour
  5. {
  6.     public DialogueNode[] node;
  7.     public int _currentNode;
  8.     public bool ShowDialogue = true;
  9.  
  10.     void OnGUI()
  11.     {
  12.         if (ShowDialogue == true) {
  13.             GUI.Box (new Rect (Screen.width / 2 - 300, Screen.height - 300, 600, 250), "");
  14.             GUI.Label (new Rect (Screen.width / 2 - 250, Screen.height - 280, 500, 90), node [_currentNode].NpcText);
  15.             for (int i = 0; i < node [_currentNode].PlayerAnswer.Length; i++) {
  16.                 if (GUI.Button (new Rect (Screen.width / 2 - 250, Screen.height - 200 + 25 * i, 500, 25), node [_currentNode].PlayerAnswer [i].Text)) {
  17.                     if (node [_currentNode].PlayerAnswer [i].SpeakEnd) {
  18.                         ShowDialogue = false;
  19.                     }
  20.                     _currentNode = node [_currentNode].PlayerAnswer [i].ToNode;
  21.                 }
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. [System.Serializable]
  28. public class DialogueNode
  29. {
  30.     public string NpcText;
  31.     public Answer[] PlayerAnswer;
  32. }
  33.  
  34.  
  35. [System.Serializable]
  36. public class Answer
  37. {
  38.     public string Text;
  39.     public int ToNode;
  40.     public bool SpeakEnd;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement