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 ferdiamg · Jul 29, 2018 at 09:37 PM · uitexttimedelayhide

Hide (not delete) text after given time..?

Hey guys, well I've read through almost every single post I could find through Google, but it just isn't working out.. I don't get it and 90% of the answer are fixed with JS or from 20XX < 2017.. which is really weird.

The following BoostPowerup class is giving my PlayerCharacter a nice little speed boost in a 2D sidescroller and its working, BUT, now I want to display a TextMeshPro Label saying "Boost activated!" for 3 seconds. I've tried doing it with deltaTime and subtracting something from a local variable to get a timer, I tried IEnumerators and Coroutines, I tried almost everything, but I think I am missing something.. It shows the text, but it never goes away again. It just stays there.

 public class BoostPowerup : Collectible {
     [Range(1, 3)] public float boostMultiplicator = 1;
     public float boostTime = 3.0f;
 
     
     public GameObject PowerUpInfo;
     public GameObject powerUpInfoText;
     private TextMeshProUGUI powerUpInfoText2;
 
     private bool active;
     
     protected override void OnPickUp(PlayerCharacter player) {
         player.Boost(boostMultiplicator, boostTime);
         DisplayInfoText();
         StartCoroutine(DisableInfoTextAfterSeconds(3, PowerUpInfo));
     }
 
     private void DisplayInfoText() {
         PowerUpInfo.SetActive(true);
         powerUpInfoText2 = powerUpInfoText.GetComponent<TextMeshProUGUI>();
         powerUpInfoText2.text = "Boost activated!";
     }
 
     private IEnumerator DisableInfoTextAfterSeconds(int seconds, GameObject obj) {
         yield return new WaitForSeconds(seconds);
         obj.SetActive(false);    
         powerUpInfoText2.text = "";
     }
 }


Any help is greatly appreciated, thanks in advance dear Unity-friends!

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 Omti1990 · Jul 30, 2018 at 07:16 AM 0
Share

Why do you feed the object "PowerUpInfo" into the "DisableInfoTextAfterSeconds" function ins$$anonymous$$d of "powerUpInfoText"?

Also does your script call that function at all? $$anonymous$$aybe add a "Debug.Log("DisableInfoTextAfterSeconds called");" to the top of the function?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sgt_Spike · Jul 29, 2018 at 09:46 PM

Hey there. I'm not too great with parameters myself so I'm not too sure what the problem with the coroutine is. Would it not be easier to have something like this:

  public class BoostPowerup : Collectible {
      [Range(1, 3)] public float boostMultiplicator = 1;
      public float boostTime = 3.0f;
  
      
      public GameObject PowerUpInfo;
      public GameObject powerUpInfoText;
      private TextMeshProUGUI powerUpInfoText2;
  
      private bool active;
      
      protected override void OnPickUp(PlayerCharacter player) {
          player.Boost(boostMultiplicator, boostTime);
          DisplayInfoText();
          
      }
  
      private void DisplayInfoText() {
          PowerUpInfo.SetActive(true);
          powerUpInfoText2 = powerUpInfoText.GetComponent<TextMeshProUGUI>();
          powerUpInfoText2.text = "Boost activated!";
          StartCoroutine(DisableInfoTextAfterSeconds());
      }
  
      private IEnumerator DisableInfoTextAfterSeconds() {
          yield return new WaitForSeconds(3f);
          obj.SetActive(false);    
          powerUpInfoText2.text = "";
      }
  }

Not sure if this is what you're looking for but see if that works.

Comment
Add comment · Show 2 · 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 ferdiamg · Jul 29, 2018 at 09:50 PM 0
Share

Sadly this doesn't change anything... Just tried it out, plus line 27 needs to be PowerUpInfo.SetActive(false); then, but sadly nothings changed...

avatar image Sgt_Spike ferdiamg · Jul 29, 2018 at 10:04 PM 0
Share

Hmm, I've never used Text$$anonymous$$eshProUGUI before so maybe that's what the problem is. What is you tried hiding the text by using SetActive ins$$anonymous$$d of .text = ""? Looking at your code it looks like powerUpInfoText is the gameobject for your text, so maybe replace 'powerUpInfoText2.text = "";' with 'powerUpInfoText.SetActive(false);'. See if that does anything good.

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

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

How to hide/reset a Text object (without disabling) 2 Answers

Type out text in sync with audioclip 0 Answers

getting unity's UI text as a string. 1 Answer

print text one character at a time with rich text 2 Answers

UI -Best Fit changes in 5.3 - how to fix the knock on effect of this change on existing text from 5.0? 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