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 MisterDaviso452 · May 26, 2014 at 06:22 AM · c#guiinterfaceondestroyexecute

GUI buttons not appearing on Destroy

So I created a final stage for my game that is only a black screen with music playing in the background, and after the music finishes a GUI button should appear that allows the player to return to the beginning.

I am not very knowledgeable in c# so I set this up where there is an object set to destroy in 10 seconds (the music) and then execute the script to bring up the script, so that it works similar to a player dying and given a "return to menu" button. The scripts I've used for previous stages have worked as intended, however this single stage will not execute the script, or they are simply hidden somehow.

The two method's I've tried using to execute it are

 void OnDestroy()
     {
         transform.parent.gameObject.AddComponent<GameOverScript4>();
         }

with the object being hit by a projectile and dying and

 void  FixedUpdate ()
         {
             Destroy(gameObject, 10);
         }
     
         void OnDestroy()
         {
             transform.gameObject.AddComponent<GameOverScript4>();
         }

Where the object just times out.

The former I used for actual player deaths and the latter I reworked from a script that executed the next stage after a set time. These lines executed exactly as intended in all other stages, but don't seem to work on this single stage.

I have no idea what other information would be helpful so please ask for details.

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
1

Answer by Midnaut · May 26, 2014 at 06:51 AM

So what you've done is destroy the GameObject you're trying to add the game over script to.

Once you destroy a GameObject it is removed from the scene, therefore no scripts will run. So if you want the script to run, add it to another object in the scene like the main camera or you could make a prefab that has the script added then instatiate.

https://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html

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 Kiwasi · May 26, 2014 at 07:54 AM 0
Share

Also key to remember that OnDestroy is not called until after the time delay in Destroy.

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

22 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

Related Questions

IGUI IOS error 1 Answer

Health Bar Percentages Problem 2 Answers

ExecuteEvents.Execute pass object to from ui 1 Answer

Distribute terrain in zones 3 Answers

How to force refresh mouse position? 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