Advertisement
Guest User

Shitty Text Adventure Implementation

a guest
Mar 25th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Game : MonoBehaviour
  7. {
  8.     //Current Dialog and display text
  9.     public Text disTxt;
  10.     public Dialog curDlg;
  11.  
  12.     void Start ()
  13.     {
  14.         updateDialog();
  15.     }
  16.  
  17.     void Update (){
  18.         //Gets input then sends to chooseOption.
  19.         for (int i = 0; i < 12; i++) {
  20.             if (Input.GetButtonDown ("b" + i)){chooseOption (i);}
  21.         }
  22.     }
  23.  
  24.     //Updates dialog text and options.
  25.     void updateDialog(){
  26.         disTxt.text = curDlg.dialogTxt + "\n\n";
  27.         for (int opt = 0; opt < curDlg.options.Count; opt++) {
  28.             disTxt.text += opt + 1 + ". " + curDlg.options [opt].optionTxt + "\n";
  29.         }
  30.     }
  31.    
  32.     //Changes active Dialog.
  33.     void switchDialog(int i){
  34.             if(curDlg.options.Count>i){
  35.             curDlg = curDlg.options [i].optionDir;
  36.         }
  37.     }
  38. }
  39. --------------------------------------------------------------------------------------------------------------------------------------
  40. using System.Collections;
  41. using System.Collections.Generic;
  42. using UnityEngine;
  43.  
  44. [CreateAssetMenu(menuName = "txtAdv/dialog")]
  45. public class Dialog : ScriptableObject {
  46.  
  47.  
  48.     [TextArea] public string dialogTxt;
  49.     public List<Option> options;
  50.  
  51.     [System.Serializable]
  52.     public class Option
  53.     {
  54.         public string optionTxt;/*Option description*/
  55.         public Dialog optionDir;/*Link to the next dialog*/
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement