Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Quest system radomized

Discussion in 'Immediate Mode GUI (IMGUI)' started by RonnerBBQ, Apr 19, 2015.

  1. RonnerBBQ

    RonnerBBQ

    Joined:
    Apr 15, 2015
    Posts:
    1
    Hi!

    I need your guys help with my code here.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NPC_Dialog : MonoBehaviour {
    5.  
    6.     public string[]answerButtons;
    7.     public string[] Questions;
    8.     bool DisplayDialog = false;
    9.     bool ActivateQuest = false;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.    
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.    
    19.     }
    20.  
    21.     void onGUI() {
    22.         GUILayout.BeginArea(new Rect (700, 600, 400, 400));
    23.             if (DisplayDialog && !ActivateQuest) {
    24.  
    25.             GUILayout.Label(Questions[0]);
    26.             GUILayout.Label(Questions[1]);
    27.  
    28.             if (GUILayout.Button(answerButtons[0])){
    29.                 ActivateQuest = true;
    30.  
    31.                 DisplayDialog = false;
    32.             }
    33.  
    34.             if(GUILayout.Button(answerButtons[1])){
    35.                 DisplayDialog = false;
    36.             }
    37.         }
    38.  
    39.         if (DisplayDialog && ActivateQuest) {
    40.             GUILayout.Label (Questions [2]);
    41.  
    42.             if (GUILayout.Button (answerButtons [2])) {
    43.                 DisplayDialog = false;
    44.             }
    45.         }
    46.        
    47.         GUILayout.EndArea ();
    48.        
    49.  
    50.     }
    51.  
    52.     void OnTriggerEnter()
    53.     {
    54.         DisplayDialog = true;
    55.     }
    56.  
    57.     void OnTriggerExit()
    58.     {
    59.         DisplayDialog = false;
    60.     }
    61. }
    This is suppose to be attached to a box collider, when you walk inside it it will trigger a few lines of questions I've put in an array and then set up two boxes with "yes I accept / no" answers. However it doesnt seem to work right know and I have no idea what it is.

    Secondly I'd like to use this as a base to let say 5 different quest givers randomized. Walk to Questgiver #1 talk-> accept-> get sent to questgiver #4-> accept -> get sent to questgiver # 2 etc

    How would I implement that?

    Would very much appreciate your help.

    Cheers