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
7
Question by AwesomeFaceHD · Sep 06, 2013 at 10:42 PM · c#javascripttextpopup

How to make text pop up for a few seconds?

Like in Call of Duty, when you get a kill, your XP pops up for a second and then disappears. How would this be done in Unity. If you could give me and example in a script, preferably C#, but JavaScript is fine too, that'd be great. Thanks in advanced.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
18
Best Answer

Answer by Eric5h5 · Sep 06, 2013 at 11:43 PM

In some function:

 if (kill) {
     StartCoroutine(ShowMessage("Abc", 2));
 }

Along with:

 IEnumerator ShowMessage (string message, float delay) {
     guiText.text = message;
     guiText.enabled = true;
     yield return new WaitForSeconds(delay);
     guiText.enabled = false;
 }
Comment
Add comment · Show 6 · 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 palakjainyourfriend · Jan 07, 2019 at 12:54 PM 0
Share

In my project, there are some errors with this code. please help me. Errors are:-

Cannot implicitly convert type 'UnityEngine.WaitForSeconds' to 'string'

The name 'kill' does not exist in the current context

'System.Collections.Generic.IEnumerable' to 'string'

avatar image Bonfire-Boy palakjainyourfriend · Jan 07, 2019 at 01:58 PM 0
Share

The if (kill) part is just showing that the StartCoroutine call is to be made when you want the kill to happen. If using the first code snippet verbatim, you'd need to have declared a boolean kill variable (and used whatever logic you need, to set it to true when you want the kill).

The type conversion error suggests that you've set the return type of your Show$$anonymous$$essage function to string ins$$anonymous$$d of IEnumerator as shown in the second snippet, which you can't do (as it's a coroutine)

avatar image KCIV4 · Jul 25, 2019 at 03:02 AM 0
Share

GUIText.text is obsolete and will be removed in future versions.

What would be the change made so this answer works?

avatar image Bonfire-Boy KCIV4 · Jul 25, 2019 at 09:24 AM 0
Share

This answer is already pretty generic, there's no mention of GUIText.text or the type GUIText.

It works if the variable guiText is of any monobehaviour type that has a text property/field. It's just showing how to do something, wait a few seconds then do something else.

So, for example, guiText could be of type UnityEngine.UI.Text.

avatar image Eric5h5 Bonfire-Boy · Jul 25, 2019 at 04:33 PM 0
Share

The answer is from 2013; what do you think Unity had for GUI functionality back then?

Show more comments
avatar image
1

Answer by dokva · Apr 13, 2016 at 03:54 PM

 public void MouseIsIn(){
         this.transform.localScale=new Vector3 (1.2f,1.2f,1f);
     }
 
     public void MouseIsOut(){
         this.transform.localScale=new Vector3 (1f,1f,1f);
     }

and use it with event trigger that sits on text @TheMagzuz

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
avatar image
0

Answer by tw1st3d · Sep 06, 2013 at 10:48 PM

Here's a quick little script for what you're looking for.

 using UnityEngine;
 using System.Collections;
 using System;
 
 class ShowTextForAFewSeconds : MonoBehavior
 {
     /*
     * Start Copying Here
     */
     
     private bool showText = false, someRandomCondition = true;
     private float currentTime = 0.0f, executedTime = 0.0f, timeToWait = 5.0f;
     
     void OnMouseDown()
     {
         executedTime = Time.time;
     }
     
     void Update()
     {
         currentTime = Time.time;
         if(someRandomCondition)
             showText = true;
         else
             showText = false;
         
         if(executedTime !== 0.0f)
         {
             if(currentTime - executedTime > timeToWait)
             {
                 executedTime = 0.0f;
                 someRandomCondition = false;
             }
         }
     }
     
     void OnGUI()
     {
         if(showText)
             GUI.Label(new Rect(0, 0, 100, 100), "Some Random Text");
     }
     
     /*
     * Stop Copying
     */
 }
Comment
Add comment · Show 6 · 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 tw1st3d · Sep 06, 2013 at 10:49 PM 0
Share

Had some problems with my script copying over, so I reposted a new answer with everything intact.

avatar image TheGeekyDead · Mar 25, 2014 at 03:59 PM 0
Share

I tried your code tw1st3d, and it says error.

 error CS0037: Cannot convert null to `float' because it is a value type

@ line:

 private float currentTime = null, executedTime = null, timeToWait = 5.0f;

Not sure how to fix that in C#

avatar image tw1st3d · Apr 03, 2014 at 02:09 AM 1
Share

Oh wow, sorry about that. Float's can't be set to a null value, so changing them to equal 0.0f will solve the error.

avatar image TheMagzuz · Mar 07, 2015 at 08:08 PM 0
Share

How do i change the size of the text then?

avatar image programer717 · Dec 03, 2018 at 11:00 PM 0
Share

To change the side just tweak the last two integers, (0, 0, 100, 100), "Some Random Text"); the two 100s and that should change the size. Hope this helps, if you are still confused just @ me and I might be able to help!

avatar image programer717 programer717 · Dec 03, 2018 at 11:00 PM 0
Share

size not side.

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

25 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

Related Questions

Distribute terrain in zones 3 Answers

GUI text blinking opacity 1 Answer

Read objects like in Penumbra 1 Answer

Multiple Cars not working 1 Answer

GUI Problem 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