Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Babilinski · Jul 06, 2011 at 05:10 PM · c#selectiondialoguequest

Quests/Dialogue (C#)

So i want to make a quest. i have a select script and i have a dialogue box. now i need to connect the two so that when a specific object is selected and then you right click the dialogue will pop up. i ran into 1 problems when i was trying to make this script 1. you are pushing more gui clips then you are popping. this is how the scrip looks for the dialogue

 using UnityEngine;
 using System.Collections;
 
 public class Speek : MonoBehaviour {
 
 // Use this for initialization
     
 public void Start ()
 {    
 CurrentMenu = MainMenu;
 DisplayMenu = false;
         Dad = false;
 }

 public void Update()
 {    
 if (Input.GetMouseButtonDown(1))
     DisplayMenu = !DisplayMenu;
     if (Input.GetKeyDown("q")){
         Dad = true;
     }
 }
 
 public void OnGUI()
 {
 if (DisplayMenu)
             
 CurrentMenu();
 if(Dad)
    dad();        
 }
 
 private delegate void MenuDelegate();
 
 private MenuDelegate CurrentMenu;
 private bool DisplayMenu;
 public bool Dad;
     
 public string nameOfGiver;
 public string nameOfDone;
 public string QuestPage1;
 public string QuestPage2;
 public string Answer;
 private bool Quest = false;
 private bool DadDone = false;

 //
 // Main menu
 //
 private void MainMenu ()
 {
 Rect MainMenuRect = new Rect((Screen.width - 280) / 2, (Screen.height - 100) / 1.03f, 630, 108);
 GUI.BeginGroup(MainMenuRect);
 GUI.Box(new Rect(10, 10, MainMenuRect.width, MainMenuRect.height),  nameOfGiver );
         GUI.Label(new Rect(25, 25, 540, 80), QuestPage1 ); 

 if (GUI.Button(new Rect(540, 80, 80, 20), "Next"))
 {   
 CurrentMenu = Next;
 }
 }
     
 private void Next(){
 Rect OptionsRect = new Rect((Screen.width - 280) / 2, (Screen.height - 100) / 1.03f, 630, 108);
 GUI.BeginGroup(OptionsRect);
 GUI.Box(new Rect(10,10,OptionsRect.width,OptionsRect.height), nameOfGiver );
 GUI.Label(new Rect(25, 25, 540, 80), QuestPage2 );
         
 if (GUI.Button(new Rect(15, 80, 80, 20), "Back"))
 {
 CurrentMenu = MainMenu;
 }
 
 if (GUI.Button(new Rect(540, 80, 80, 20), "Okay"))
 {
 DisplayMenu = false;
 }
 }
             
 private void dad(){
 Rect OptionsRect = new Rect((Screen.width - 280) / 2, (Screen.height - 100) / 1.03f, 630, 108);
 GUI.BeginGroup(OptionsRect);
 GUI.Box(new Rect(10,10,OptionsRect.width,OptionsRect.height), nameOfGiver );
         GUI.Label(new Rect(25, 25, 540, 80), Answer );    
 
 if (GUI.Button(new Rect(15, 80, 80, 20), "Back"))
 {
 CurrentMenu = MainMenu;
 }

 if (GUI.Button(new Rect(540, 80, 80, 20), "Okay"))
 {
 DisplayMenu = false;
 Quest = true;
 }                
 }
     
     
     }

}
}
}

and this is how the targeting script looks like

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class TargettingQuest : MonoBehaviour {
     public List<Transform> targets;
     public Transform selectedTarget;
     public GameObject target;
      
     
     private Transform myTransform;
         
     // Use this for initialization
     void Start () {
         targets = new List<Transform>();
         selectedTarget = null;
         myTransform = transform;
         
         AddAllEnemies();
     }
     
     public void AddAllEnemies() {
         GameObject[] go = GameObject.FindGameObjectsWithTag("Enemy");
         
         foreach(GameObject enemy in go)
             AddTarget(enemy.transform);
     }
     
     public void AddTarget(Transform enemy) {
         targets.Add(enemy);
     }
     
     private void SortTargetsByDistance() {
         targets.Sort(delegate(Transform t1, Transform t2) {
                 return Vector3.Distance(t1.position, myTransform.position).CompareTo(Vector3.Distance(t2.position, myTransform.position));
                 });
     }

     #region
     //This is added by adrian 
     #endregion

     //if we do not have an enemy targeted ywt, then find the clostest one and target him
     //if we do have an enemy targeted, then get the next target
     //if we have the last target in the list, then get then first target in the list
     private void TargetEnemy() {
         if(selectedTarget == null) {
             SortTargetsByDistance();
             selectedTarget = targets[0];
         }
         else {
             int index = targets.IndexOf(selectedTarget);
             
             if(index < targets.Count - 1) {
                 index++;
             }
             else {
                 index = 0;
             }
             DeselectTarget();
             selectedTarget = targets[index];
         }
         SelectTarget();
     }
     private void SelectTarget() {
         selectedTarget.renderer.material.color = Color.red;
 }

     private void DeselectTarget() {
         selectedTarget.renderer.material.color = Color.white;
         selectedTarget = null;
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKeyDown(KeyCode.Tab)) {
             TargetEnemy();
         }
         float distance = Vector3.Distance(target.transform.position, transform.position);
         
         Vector3 dir = (target.transform.position - transform.position).normalized;
         
         float direction = Vector3.Dot(dir, transform.forward);
         if(distance < 2.5f) {
             if(direction > 0) {
             Speek pa = (Speek)GetComponent("Speek");
         pa.Dad = true;
     }
 }
 }
 }

How can i set the distance so i cant select the object when it more then 1 yrd away from me?

how can i make it so when i press okay the quest begins .. ( in this case the quest asks you to go talk to your dad. so i want it to be that if you talk to your dad before you get the quest noting should happen and then when you press okay another script activates that lets you to clame your reward.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chris D · Jul 06, 2011 at 06:04 PM 0
Share

So...I cleaned up your code a bit but it's still kind of a mess to read. In the future, please try to make it easier on everyone by using proper indentation and $$anonymous$$imizing the amount of line breaks in whatever you post.

avatar image Babilinski · Jul 06, 2011 at 06:17 PM 0
Share

sorry, i'm new to scripting

avatar image jester · Jul 06, 2011 at 07:42 PM 0
Share

each call to gui.begingroup() needs to be closed by a gui.endgroup(), which comes after the last gui element you want in the group. that will fix the "pushing more gui clips" error that you're having.

avatar image asafsitner · Jul 06, 2011 at 08:07 PM 0
Share

To 'activate' your quest you can declare a bool and flag it as true after the player clicked 'okay'. When they start conversation with the father you check to see the state of that bool and pop the appropriate dialog/script.

avatar image Babilinski · Jul 06, 2011 at 08:37 PM 0
Share

So I put the completion script and the dialogue script in to two different scripts. how can i link them so that when i press okay it makes the variable in the other script turn true?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a Quest system 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

I need help understanding why this variable returns null. 1 Answer

Character Selection Scene Help 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges