Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Jul 30, 2018 at 05:04 PM by singingstranger for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by singingstranger · Jul 17, 2018 at 03:58 PM · getkeydowngetkeydialoggetkeyup

Dialogue with GetKey - Codes

Hello everyone, I'm new to programming but have been able to make a basic demonstration for a game that I am now trying to flesh out a bit. But I keep running into a problem. I tried making a dialog system that ended up looking a bit like this:

public float conversation;

void Update(){

 if (Input.GetKeyDown(KeyCode.Space)){
     panel.SetActive(true);
     text.text="Hello.";
     conversation=1;
 }
 if (conversation==1 && Input.GetKeyDown(KeyCode.Space)){
     conversation=2;
     text.text="What's up?"; 
 }    
 if (conversation==2 && Input.GetKeyDown(KeyCode.Space)){            
     panel.SetActive(false);

}

Basically what happens is I run the script (the trigger works fine so far) and it just skips through the entire dialog to the end. I've tried using .GetKeyDown, .GetKeyUp... and even having a float that would count down (countdown-= Time.deltaTime) and even to only read this part of the script if it is countdown<=0. None of these solutions has worked.

If anyone has ideas, please feel free to share because I'm at a bit of a loss.

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

  • Sort: 
avatar image
0

Answer by Glurth · Jul 17, 2018 at 04:11 PM

There is a single keyword you need to fix this: "else"
Notice that if the first condition is true- you MAKE the second condition true (and so on).
So, if you just add an else before if (conversation==1.. (and all those that follow), it will ensure that only ONE dialog option get executed per call to Update()

Alternatively: you could use the 'return' keyword, at the end of each dialog option. But this assumes there is nothing else in update you need to execute lower down. Also, take a look at the c# case..switch command, perfect for this sort of thing!

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 singingstranger · Jul 30, 2018 at 05:02 PM 0
Share

Thank you so much! It worked like a charm... It was a bit embarrassing, having all sorts of things run perfectly fine but no functioning dialog system in a story heavy game.

Follow this Question

Answers Answers and Comments

89 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 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

Change view if key is pressed 4 Answers

Input.GetKey question 1 Answer

Update GetKey If Statements both playing instantly 1 Answer

Can/how do I set up a boolean to continue an animation after button press 1 Answer

AudioSource does not work for some reason 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