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 /
avatar image
0
Question by CJY01 · Feb 16, 2020 at 01:26 PM · texttextbox

How do I reveal a text for a moment before making it disappear?

The player is supposed to pick up a note (represented by a square block here) and a message appears telling the player that their "journal" has been updated. The text should not destroy itself as technically it needs to appear multiple times whenever the player picks up a "note". I managed to simulate this by having the square block destroy itself upon click and change a Boolean to true to get the text to reveal itself. However, I can't get the text reveal to appear long enough to notify the player that their "journal" has been updated. I tried to use a for loop which obviously failed and I searched up online and found out about IEnumerator and things like that but I don't know how to implement them. How do I do this text reveal thing? (I'm using Unity 2019.2.17f1)

 public void OnMouseDown()
     {
         if (Input.GetMouseButtonDown(0))
         {
             Destroy(gameObject);
             Debug.Log("Pressed");
             NotePickedUp = true;
             Debug.Log("Note has been picked up");
         }
         if (NotePickedUp == true)
         {
             for (int i = 0; i < 3; i++)
             {
                 canvas.transform.GetChild(0).gameObject.SetActive(true);
                 Debug.Log("Counting...");
             }
             canvas.transform.GetChild(0).gameObject.SetActive(false);
 
 
         }
     }
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 utzsar · Feb 16, 2020 at 02:17 PM

here's how you would implement the IEnumerator for this, which would be the easiest method here if you want it to just pop up for a set amount of time and then go away.

 IEnumerator ShowNoteText()
 {
 
     canvas.transform.GetChild(0).gameObject.SetActive(true);
 
     yield return new WaitForSeconds(3); // set for however long you want it open.
 
     canvas.transform.GetChild(0).gameObject.SetActive(false);
 
 }

then when the note is picked up on your mouseclick function, put this

 StartCoroutine(ShowNoteText());


you wont even need the notepickedup=true bool, unless you're using that for something else too.

fyi, the reason your for loop isn't working for this is because it iterates too fast. that function would have counted through three items in fractions of a second. for loops like that are for iterating through groups of items quickly, not counting time. to do that you would have to save the current Time.time as a float and compare it to another captured Time.time, but that's prolly way more complex than what you need in this instance. IEnumerators are perfect for this kinda thing :D

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

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

One text box after another 2 Answers

Unity 2D - Text UI and Textbox scripting issue - HELP ASAP! 2 Answers

Text Mesh Pro detect automatic word wrap line break in script 0 Answers

One Text box after another problem 1 Answer

Populate Text Box until it's full 0 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