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 robbiek · Feb 28, 2012 at 02:12 PM · guitextdestroy

Destroy text

I have some GUI text on my screen that appears when the game starts. I'm trying to get it to be destroyed when you press the E button. I wrote a script to do this, but it doesn't appear to be working although I feel that its done right.

 import UnityEngine



class IntroText(MonoBehaviour):

 def OnGUI():

     if (Input.GetKeyDown(KeyCode.E)):

         Destroy(self)

the scripts in boo, and its attached to the GUitext.

Comment
Add comment · Show 2
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 JinxM · Feb 28, 2012 at 04:20 PM 0
Share

I didn't put this as an answer since I'm not familiar with Boo and this might not solve your problem, but I notice one issue is that you're putting Input code in OnGUI(). This should really be in Update() ins$$anonymous$$d.

avatar image robbiek · Feb 28, 2012 at 04:55 PM 0
Share

I've tried putting it in Update() as well.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by squid808 · Feb 28, 2012 at 07:01 PM

Hi there, when you are calling Destroy(self) you're destroying the script itself - not the object entirely. If you want to see this happen, you can select the object with the GUIText attached to it in the Hierarchy when running, and keep an eye on the inspector when it runs. But, as JinxM mentioned, you'll need to use Update(). As far as I know, OnGUI() is called every frame but is instead used for drawing GUI objects (for more info, see this link).

The following is assuming this is attached to a game object that has the GUIText also attached. If you want to delete the GUIText component but not the game object, you can do Destroy(self.guiText). If you want to remove the entire object, you can call Destroy(self.gameObject).

 import UnityEngine
 
 class IntroText(MonoBehaviour):
 
     def Update():
     
         if (Input.GetKeyDown(KeyCode.E)):
     
            #This should remove your game object entirely
            Destroy(self.gameObject)

I hope this helps out.

Comment
Add comment · Show 1 · 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 azmundai · Apr 12, 2013 at 12:53 AM 0
Share

Thanks!! :)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't destroy an arrray with GUI Text 1 Answer

Script to make a GUI texture disappear after a set amount of seconds? 2 Answers

Story Text to GUI Boxes 0 Answers

Trying to make an ASCII UI based game 0 Answers

GUI Appear Help 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