• 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
Question by importguru88 · Aug 31, 2016 at 07:05 PM · texttextmeshhowhow-to

How do I get Text Mesh to appear in the scene ten seconds later and disappear

I need the text mesh to appear and disappear in scene right at ten seconds or less . I got most of the code done . I only got one error :

(7,12): error CS0118: oik.text' is a field' but a `type' was expected

Here is my code :

 using UnityEngine;
   using System.Collections;
   using UnityEngine.UI;
   
   public class oik : MonoBehaviour {
   
    private text text;
 
  
   
   
        void ShowMessage(string message, float timeToShow = 10)
    {
        StartCoroutine(ShowMessageCoroutine(message, timeToShow));
    }
       
        IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
    {
 
        while (timeShown < timeToShow)
        {
            timeShown += Time.deltaTime;
            yield return null;
        }
 
        text.text = " The Reqiure Score is 1700" ;
    }
   }
   
Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by importguru88 · Sep 01, 2016 at 02:23 AM

I have done that nothing has change the text is their on screen . Here is my code now :

 using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class oik : MonoBehaviour {
    
     private Text text;
  
       public float timeShown = 0f;
    
    
         void ShowMessage(string message, float timeToShow = 10)
     {
         StartCoroutine(ShowMessageCoroutine(message, timeToShow));
     }
        
         IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
     {
  
         while (timeShown < timeToShow)
         {
             timeShown += Time.deltaTime;
             yield return null;
         }
  
         text.text = " The Reqiure Score is 1500" ;
     }
    }
Comment

People who like this

0 Show 10 · 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 eldorno · Sep 01, 2016 at 02:41 AM 0
Share

Sorry, if I understand you correctly, you want it to display the message for 10 seconds and then hide it? If so, then this should be the code you want:

 IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
 {
     // Show the text
     text.text = message;
 
     // Wait for 10 seconds
     float timeShown = 0f;
     while (timeShown < timeToShow)
     {
         timeShown += Time.deltaTime;
         yield return null;
     }
 
     // Hide the text
     text.text = "";
 }
avatar image importguru88 eldorno · Sep 01, 2016 at 03:41 AM 0
Share

I am not using text mesh. I am using ui text. Will this still work for ui text ?

avatar image eldorno importguru88 · Sep 01, 2016 at 06:08 AM 0
Share

Yes, definitely. I've just got home and tried it on my own computer, and the code I gave you is working as expected. If it's not working for you, then there must be something else causing the issue. Could you provide a screenshot of the Inspector or something to give us more detail?

Show more comments
avatar image

Answer by instruct9r · Aug 31, 2016 at 07:11 PM

 public class oik : MonoBehaviour {
    
     private Text text;


The definition of Text variable should be with Capital letter...

Comment

People who like this

0 Show 4 · 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 importguru88 · Aug 31, 2016 at 07:37 PM 0
Share

I don't have that error any more . I now got another error : (20,16): error CS0103: The name `timeShown' does not exist in the current context

 using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class oik : MonoBehaviour {
    
     private Text text;
  
   
    
    
         void ShowMessage(string message, float timeToShow = 10)
     {
         StartCoroutine(ShowMessageCoroutine(message, timeToShow));
     }
        
         IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
     {
  
         while (timeShown < timeToShow)
         {
             timeShown += Time.deltaTime;
             yield return null;
         }
  
         text.text = " The Reqiure Score is 1700" ;
     }
    }
avatar image jjesh importguru88 · Aug 31, 2016 at 08:16 PM 0
Share

You've defined timeToShow, but I don't see anywhere you've set up timeShown. Is timeShown supposed to be a variable from another script?

avatar image importguru88 jjesh · Aug 31, 2016 at 08:25 PM 0
Share

What do mean variable from another script ? Do you mind testing my script ?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

56 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

Related Questions

How do I change my health bar to be text only 2 Answers

I can't change the text mesh 1 Answer

Mesh with Transparent material makes TextMesh in front of it invisible 3 Answers

TextMesh Pro Page content 2 Answers

How to treat multiple text meshes as if they would be a single one. 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