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 /
  • Help Room /
avatar image
0
Question by Nitoken · May 06, 2016 at 09:55 AM · npcdialoguedialoghealth

NPC Dialog

Hi, I try to make my own NPC dialog script. I figured out that way:

1.Lock players movement (so he cant run with chat opened)
2.Display first msg from NPC into text in panel + 3 choose options.
(1 yes, 2 no, 3 cut dialog)
3.Code waits till player press one button. <-- ACTUAL PROBLEM #1 --
Every button have own value. Btn3 = 3, Btn2 = 2, etc.
4.Code have one int variable = 0 and after button pressed change that value by button's value.
5.After that code switch(variable)
case 1: case 2: case 3: <-- third always finish dialog
Every case have NPC's answer.
6.After switch int variable = 0;
7.Again wait for players press button, and again variable change value.
Repeat that till dialog finish.
When dialog ends:
Put dialog panel out of canvas(invisible for player), unlock players movement.

Does it have sense?
IMO #1 problem is force code to wait till player choose button.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BTCallahan · May 06, 2016 at 07:51 PM

To keep the player from moving around, you could have a boolean called "isTalking". If it's active, the player's input is disabled. For example:

 public bool isTalking;
 
 void FixedUpdate(){
 
 if(isTalking){
 //do something
 
 }else{
 //get controller input
 }
 }

For the buttons, I recommend having a child of the canvas, say a panel, that starts out deactivated (and thus hidden) which would have several buttons that could be hidden or unhidden using a script depending on the number os responses you needed to display.

Regarding the dialogue, I think using a custom class to store it would suit you best. Take the following:

 public class DialogueStorage{
 
 public string npcText;
 
 public string[] playerTexts;
 
 public int[] responceNumberToGoTo;
 
 public DialogueStorage(string npcText, string[] playerTexts, int[] responceNumberToGoTo){
 this.npcText = npcText;
 this.playerTexts = playerTexts;
 this. responceNumberToGoTo = responceNumberToGoTo;
 }
 }

Each NPC could have an array of the DialogueStorage objects.

 public class NPC : MonoBehaviour{

 public DialogueStorage[] NPC_Dialogue;

 public string GetNPC_Responce(int responceNumber){

 return NPC_Dialogue[responceNumber].npcText;
 }

 public string[] GetPlayerResponce(int responceNumber){

 return NPC_Dialogue[responceNumber].playerTexts;
 }

 public int[] GetResponceNumbers(int responceNumber){

 return NPC_Dialogue[responceNumber].responceNumberToGoTo;
 }

 }
 

The script could then check the length string array returned by the GetPlayerResponce method to determine the number of button that should be visible and the array itself to set the button texts.

I hope this helps you out.

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

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

54 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How can i make an Dialogue for an NPC 0 Answers

Camera-movement within another camera 1 Answer

How to continue dialog automatically (without pressing buttons)? 1 Answer

How to show dialogue when triggered by collision with npc collide box? 0 Answers

Errors on Script? 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