Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 DMCH · Mar 04, 2013 at 02:03 PM · guidialog

Start of level Dialogue

Hello,

I'm working on a 2D game and looking for some advice on how to program a small section of dialogue at the start of every level (in game).

I'd like a character portrait, and room for some dialogue next to that. I'd also like the player to be able to choose dialogue occasionally. I understand fairly well what GUI components I need for each part, but am less certain on how to store and set up the changes of the portrait and text. Any advice would be welcome, and thanks for reading!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Professor Snake · Mar 04, 2013 at 04:14 PM

A relatively complex solution would be to store all the page data in arrays, as well as the buttons in each page and their functions. An important variable to understand is pageChanges. I use that to show which page has what kind of buttons, and which page they lead to.

Each entry should have this format: "currentPage"-"pageToGoTo" (so, 1-3 would mean that we should create a button in page 1 that takes us to page 3. For its name, we are going to use the buttonNames array; for instance, if "1-3" is in position X of the pageChanges array, we are going to use buttonNames[X] to name the button that is in page 1 and takes you to page 3.

We can also detect whether the entry is named "Exit" and leave the dialogue with it.) The arrays buttonNamesForPage and pageChangesForPage should have a length equal to the maximum amount of dialogue available in a page.

They are ultimately unnecessary, but they will simplify things.

 var pageChanges:String[];
 var pageChangesForPage:int[];
 var buttonNames:String[];
 var buttonNamesForPage:String[];
 var pageToShow:int=0;
 var pageTitles:String[];
 var pageTexts:String[];
 var pageImages:Texture2D[];
 function OnGUI(){
 
 //Draw a gui box with the title being pageTitles[pageToShow]
 //draw the pageImages[pageToShow] text.
 //draw the page text the same way.
 
 //Now we are going to parse the pageChanges data to see how many buttons the page will have
 var thisPagePointer:int=0;
 for(var i:int=0;i<pageChanges.length;i++){
 var textPointer:String[]=pageChanges[i].Split("-"[0]);
 if(int.Parse(textPointer[0])==pageToShow){
 pageChangesForPage[thisPagePointer]=textPointer[1];
 buttonNamesForPage[thisPagePointer]=buttonNames[i];
 thisPagePointer++;
 }
 }
 //Now we have assigned all the data we need to our arrays, time to make buttons
 GUILayout.BeginVertical(); //you need a GUILayout, it's up to you to customise the coordinates of the GUI.BeginArea that should go in front of it.
 for(var j:int=0;j<thisPagePointer;j++){
 if(GUILayout.Button(buttonNamesForPage[j])){
 if(pageChangesForPage[j]=="Exit")
 QuitDialogue();
 else
 pageToShow=int.Parse(pageChangesForPage);
 }
 }
 
 }
 
 function QuitDialogue(){
 //do things to stop the dialogue and start playing
 }

It's a somewhat complex solution but it should get the job done. I'll give you setup examples in a bit.

Examples: Let's assume that in the first dialogue box you want to give the player two choices, a "Hi" choice that takes the user to another page and an "Exit" choice. You also want the second page to be the last and only contain an "exit" choice. This is how the arrays should be set up:

 pageChanges: ["0-1","0-Exit","1-Exit"] //Exclude the brackets in all of these
 pageChangesForPage:  Set length to 2
 buttonNames: ["Hi","Leave","Leave"]
 buttonNamesForPage: Set length to 2
 pageTitles: ["You see a person down the street","You greet the person"]
 pageTexts: ["What do you say to the person?","The person greets you as well and continues down the road"]
 pageImages: [image of you , image of stranger]

The buttons will be created in the order that the page changers are found in the pageChanges array, so if the array looks like [...,"1-3","0-4","0-2",...] , the button that takes you to page 4 will be shown first in page 0.

Comment
Add comment · Show 1 · Share
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 DMCH · Mar 04, 2013 at 11:04 PM 0
Share

Thanks for the assist, Prof. $$anonymous$$anaged to get a basic implementation of in-game dialog in place.

avatar image
1

Answer by poncho · Mar 04, 2013 at 03:18 PM

well, you will need gamestates, like, Start, Dialogue, Game, Pause, End, Win, Lose in this Dialog, you could use a GuiBox, a GuiTexture, and a GuiText, a wholetext variable and a textbytime, a timecounter, depending on the timecounter, set a maxtime per character (maxtimeperchar), so when the timecounter reaches maxtimeperchar, you add a letter from the wholetext to the textbytime, that way you will show the letters one by one depending on your maxtimeperchar variable, the portrait would be even easier, you just need a public texture per character(people) and when that char is talking, you just need to change the portrait texture, that would be all you need for that dialogue system, at least is how i made it, good luck and happy coding =D

Comment
Add comment · Show 1 · Share
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 DMCH · Mar 04, 2013 at 11:05 PM 0
Share

Thanks, poncho! Got basic in game dialog working. $$anonymous$$uch appreciated!

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I have a custom editor for a class which work's fine, but how do i refrence it in another class and get it ti appear? 1 Answer

I am trying to make an RPG style dialog script 2 Answers

How to prevent GUI dialog windows from overlapping? 1 Answer

Editor Input Dialog 2 Answers

Showing Time With GUI.Label 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