Advertisement
AndrewRosyaev

InstantiateDialog.cs

May 17th, 2016
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class InstantiateDialog : MonoBehaviour
  6. {
  7.     public TextAsset ta;
  8.     public Dialog dialog;
  9.     public int currentNode;
  10.     public bool ShowDialogue;
  11.  
  12.     public GUISkin skin;
  13.  
  14.     public List<Answer> answers = new List<Answer>();
  15.  
  16.     void Start ()
  17.     {
  18.         dialog = Dialog.Load (ta);
  19.         skin = Resources.Load ("Skin") as GUISkin;
  20.     }
  21.  
  22.     void Update()
  23.     {
  24.         UpdateAnswers ();
  25.     }
  26.  
  27.     void UpdateAnswers ()
  28.     {
  29.         answers.Clear ();
  30.         for (int i = 0; i < dialog.nodes [currentNode].answers.Length; i++)
  31.         {
  32.             if(dialog.nodes [currentNode].answers [i].QuestName==null||dialog.nodes [currentNode].answers [i].NeedQuestValue==PlayerPrefs.GetInt(dialog.nodes [currentNode].answers [i].QuestName))
  33.             answers.Add (dialog.nodes [currentNode].answers [i]);
  34.         }
  35.     }
  36.  
  37.     void OnGUI()
  38.     {
  39.         GUI.skin = skin;
  40.         if (ShowDialogue) {
  41.             GUI.Box (new Rect (Screen.width / 2 - 300, Screen.height - 300, 600, 250), "");
  42.             GUI.Label (new Rect (Screen.width / 2 - 250, Screen.height - 280, 500, 90), dialog.nodes [currentNode].NpcText);
  43.             for (int i = 0; i < answers.Count; i++)
  44.             {
  45.                 if (GUI.Button (new Rect (Screen.width / 2 - 250, Screen.height - 200 + 25 * i, 500, 25), answers [i].text, skin.label))
  46.                 {
  47.                     if(answers[i].QuestValue>0)
  48.                     {
  49.                         PlayerPrefs.SetInt (answers [i].QuestName, answers[i].QuestValue);
  50.                     }
  51.                     if (answers [i].end == "true")
  52.                     {
  53.                         ShowDialogue = false;
  54.                     }
  55.                     if (answers [i].RewardGold > 0)
  56.                     {
  57.                         Character.Gold += answers [i].RewardGold;
  58.                     }
  59.                     currentNode = answers [i].nextNode;
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement