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 goranr · Feb 25, 2012 at 10:26 AM · yieldkeymessage

Showing and hiding guiText after a key is pressed

Here is the thing. First I'm showing an animation of a rotating cube, then after 4 seconds I display a speech ballon (Gui Label). The balloon should be visible until the user presses the Spacebar. After this another speech ballon is shown. Then again the user needs to press the Spacebar to hide it. In total I show 3 speech ballons and after that is finished I play an animation. Here is the code:

 function Intro()
 {
     yield WaitForSeconds(4);
     gameObject.Find("Cubo Text").SendMessage("Show",0); // This calls a function that displays the correct message
     while (!Input.GetKey("space")) yield;
     gameObject.Find("Cubo Text").SendMessage("Show",1); 
     while (!Input.GetKey("space")) yield;
     gameObject.Find("Cubo Text").SendMessage("Show",2);
     while (!Input.GetKey("space")) yield;
     gameObject.Find("CuboB").animation.Play("roll");
     
 }

This function is called in Start() . The problem is that I can see the first speech balloon, but after pressing the Spacebar I can't see any other baloon and the animation starts inmediatly. Any ideas why this happens and how to solve it?

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
Best Answer

Answer by Kleptomaniac · Feb 26, 2012 at 12:02 AM

Hey there!

This should not be called in Start(). Start is literally only called at the initialisation of a script, so at the beginning of runtime. After the start of runtime, it is not called again. Therefore after the very start of runtime, your key inputs aren't being received. That's what Update() is for!

I'd say go about you're script like this:

var balloonNumber : int = 0;

function Start() { cuboText = gameObject.Find("Cubo Text"); cuboB = gameObject.Find("CuboB"); }

function Update() {

 InvokeRepeating("SpeechBubbles", 4, 0);

}

function SpeechBubbles() { cuboText.SendMessage("Show", balloonNumber); if (Input.GeyKeyDown(KeyCode.Space) && balloonNumber < 2) { balloonNumber++; } if (balloonNumber == 3) { cuboB.animation.Play("roll"); } }

See how you go with that. Klep

Comment
Add comment · Show 7 · 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 Kleptomaniac · Feb 26, 2012 at 04:14 AM 0
Share

I just realised that you wanted to do the animation last. Edited the code to account for this and also changed a mistake which would have allowed for infinite presses of the spacebar. Good luck with your game!

avatar image goranr · Feb 27, 2012 at 04:56 AM 0
Share

Thank you very much for the answer. Yeah, after a longer inspection I too realized that the Get$$anonymous$$eyDown 's value was not updating 'cause it only runs once u__u. I tried your solution, however I still have issues. The speech bubbles are being shown for a fraction of second, but after that they dissapear (completely ignoring the request for the spacebar, which by the way had a small mistyping Input.Gey$$anonymous$$eyDown ins$$anonymous$$d of Input.Get$$anonymous$$eyDown :p). Do you know why???

avatar image Kleptomaniac · Feb 27, 2012 at 10:14 AM 0
Share

Thanks for noticing my mistyping of Get$$anonymous$$eyDown. I'm editing the code with (hopefully) the final revisions. I think it should work. It's also a lot simpler now.

avatar image Kleptomaniac · Feb 27, 2012 at 10:28 AM 0
Share

O$$anonymous$$, I edited. I don't think my revision seems to be updating so I'll just chuck it in this comment:

 var balloonNumber : int = 0;
 
 function Start() {
     cuboText = gameObject.Find("Cubo Text");
     cuboB = gameObject.Find("CuboB");
 }
 
 function Update() {
 
     InvokeRepeating("SpeechBubbles", 4, 0);
 
 }
 
 function SpeechBubbles() {
     cuboText.Send$$anonymous$$essage("Show", balloonNumber);
     if (Input.Gey$$anonymous$$eyDown($$anonymous$$eyCode.Space) && balloonNumber < 2) {
         balloonNumber++;
         } if (balloonNumber == 3) {
             cuboB.animation.Play("roll");
         }
     }

See how that goes. If it doesn't work, just tell me.

avatar image goranr · Feb 27, 2012 at 11:31 AM 0
Share

It works!!!!! I've been trying to solve this ting for over 2 days... <3 <3 <3

Before concluding this would you $$anonymous$$d explaining me how InvokeRepeating works????

Show more comments

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

6 People are following this question.

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

Related Questions

Returning from and waiting for a Message function 0 Answers

How do I have Unity Wait for a keypress? 1 Answer

Change ctrl key unity editor collider 2D 0 Answers

Multiple key. Press order 0 Answers

Select object with mouse and hide its children with key, 2 Answers


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