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 Doneyes · Aug 08, 2012 at 02:42 PM · objectdestroy

How do I delete a gamebject that is not the one my script is in?

I have a script that destroys the gameobject the script is in when a variable reaches 0. I really need to destroy the parent though.

So Object A is inside of Object B. The script is inside of Object A. I need to destroy Object B. Can anyone help me out?

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

2 Replies

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

Answer by KiraSensei · Aug 08, 2012 at 02:51 PM

Create a variable and give it to eat to your script !

In your script :

 var myObjectToDelete:GameObject;
 
 function Update()
 {
 Destroy(myObjectToDelete);
 }

Don't forget to put your game object in the inspector of the script. This should work.

Very important : put the destroy line at the very end, if you do something after, there will be errors ...

Comment
Add comment · Show 5 · 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 Doneyes · Aug 08, 2012 at 05:16 PM 0
Share

Thank you! I kind of forgot about this but forgot the lines of code for it anyways. It's working great, much appreciated.

avatar image fafase · Aug 08, 2012 at 05:21 PM 0
Share

Actually, @$$anonymous$$iraSensei, Destroy is delayed at the end of the current update.

avatar image KiraSensei · Aug 08, 2012 at 05:28 PM 0
Share

Yes, thanks for telling it :). Please validate the answer if it's ok @Doneyes !

avatar image Doneyes · Aug 08, 2012 at 10:06 PM 0
Share

I'm not aware how to do that.

avatar image KiraSensei · Aug 08, 2012 at 10:18 PM 0
Share

At the left of answers, you have thumbs up, a number, thumbs down and a check icon, click on the check icon :)

avatar image
1

Answer by screwworkn · Aug 08, 2012 at 02:57 PM

I haven't tested this code but I believe you should be able to do the following

 GameObject ObjectB = ObjectA.transform.parent.gameObject;

Then you can destroy ObjectB

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

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

Getting all Object to go next scene. 1 Answer

Trying to Destroy Object when Wave starts 1 Answer

particle effect activation 1 Answer

Destroy object problem. 1 Answer

How to make an event happen after an object is collided with 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