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 Cazabitz · Jan 07, 2013 at 01:08 AM · guitext

How do I Enable Gui Text On Object Destroy?

I need to know how to enable the text "1/4 Notes Collected" when I left click on a sheet of paper. The paper already makes it's sound and destroy's when I click it. Now all I need to do is have the text listed above show for 3 seconds. In js, how would I do this? Here's my script. (It's very messy, I had a friends help me with it)

 var information: String; 
 private var guiOn = false;
 private var rect: Rect;
 
 function OnMouseDown(){
     guiOn = true; 
     rect = Rect(Input.mousePosition.x, Input.mousePosition.y, 300, 100);
     yield WaitForSeconds(3);
     guiOn = false;
 }
 
 function OnGUI(){
     if (guiOn){
         GUI.Label(rect, information);
     }
 }
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 whydoidoit · Jan 07, 2013 at 04:42 AM

I'm guessing that script is attached to the same game object as the one that is being destroyed. That's your problem - you are destroying it and still trying to use OnGUI on it! So you need to not destroy it until after 3 seconds to give the GUI time to show. You might just want to turn the renderer and collider off before that.

     renderer.enabled = false;
     collider.enabled = false;

This will work if it's just one object - if it is itself the parent of other objects then you will have to get all of them:

     foreach(var r : Renderer in GetComponents(Renderer))
     {
          r.enabled = false;
          if(r.collider)
               r.collider.enabled = false;
     }

This will work if all of your colliders are on objects with renderers - otherwise you would need a second for loop for the colliders.

Comment
Add comment · Show 3 · 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 Cazabitz · Jan 07, 2013 at 08:04 PM 0
Share

(This is the script that destroys the note and plays a sound. )

var keyPickupSound : AudioClip;

function On$$anonymous$$ouseDown (){

//Play $$anonymous$$ey Pickup Sound if (keyPickupSound) AudioSource.PlayClipAtPoint(keyPickupSound, transform.position);

 Destroy(gameObject);
   

}

avatar image whydoidoit · Jan 08, 2013 at 01:11 PM 0
Share

So exactly - the problem is that this script immediately destroys the object - you need to get it to wait for 3 seconds - otherwise it isn't there to display the GUI

avatar image DanielJF · Jan 08, 2013 at 01:39 PM 0
Share

$$anonymous$$aybe you can try to disable it ins$$anonymous$$d of destroy it and a invoke could help aswell

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

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers

rocket Launcher GUI Text probleme 1 Answer


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