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 Danicted · May 24, 2015 at 02:39 PM · c#2d2d platformer

Dialouge System [SOLVED]

Hello there! I am trying to create a dialogue system were everytime you press "W" it will go to the next dialouge. The problem I have encountered is that when I press W, it detects the press multiple times, and it instantly jumps to the last dialogue, before closing automatically.

Here is my current script:

     void OnGUI(){
         if(Dialog1){
             if(GUI.Button (new Rect(500,550,520,120), "Oh, you're finally awake! My name is Robo. Can you tell me a bit about yourself?\n What's your name?"));
             username = GUI.TextField ( new Rect (500, 530, 520, 20), username, 60);
 
         }
 
         if(Input.GetKey(KeyCode.W)&& Dialog1){
             Dialog1 = false;
             Dialog2 = true;
         }
 
 
         if(Dialog2){
             if(GUI.Button (new Rect(500,550,520,120), "Oh, Hello " + username));
 
         }
 
 
         if(Input.GetKey(KeyCode.W)&& Dialog2){
             Dialog2 = false;
             Dia3 = true;
         }
 
         if(Dia3){
             if(GUI.Button (new Rect(500,550,520,120), "I have a quest for you " + username + ".\n Find a key hidden somewhere around here, and bring it back to me. \n \n *To pick up something, stand close to it and press ''S''*"));
         }
 
         if(Dia3 && Input.GetKeyUp(KeyCode.W)){
             Dia3 =false;
         }
 
     }



SOLVED: I solved it by changing Input.GetKeyDown to Input.GetKeyUp, and change between these two for every dialogue.

Comment
Add comment · Show 1
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 Danicted · May 24, 2015 at 05:30 PM 0
Share

Still haven't figured it out. I removed dialog2, which fixed the problem, but if I want to end dialog2 by pressing ''w'' it will simply end the dialog at dialog 1 ins$$anonymous$$d of showing dialog2.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Multifred · May 26, 2015 at 03:58 AM

You should use GetKeyDown instead of GetKey.

As the doc says GetKeyDown "Returns true during the frame the user starts pressing down the key identified by name." and it seems that what you are looking for. It's the same for GetButton vs GetButtonDown or GetMouseButton vs GetMouseButtonDown

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 Danicted · May 26, 2015 at 11:41 AM 0
Share

Yeah, I tried that too, I have seemed to figure it out though; It should work to put Input.Get$$anonymous$$eyDown, then Get$$anonymous$$eyUp, and change between each dialouge. It have worked to now. :)

Thanks for your answer though!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D - Creating a basic teleport system 0 Answers

Cannot make bullet shoot right 2 Answers

In my 2D platformer game, how would I create a height marker?, 1 Answer

Checking for an object at a certain position 2 Answers

2D Image not appearing in game but only in scene 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