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 Michellia · Jul 25, 2014 at 07:17 PM · prefabdestroyparticle

Destroy an instantce of a prefab object

Greetings all I have researched this for days. Found many answer to similar questions.

Here is the short of it. Latest version of unity3d free one Doing a 2D shoot ( start from the basic I always say )

I have a fighter and a enemy. all works great. They ram each other they die. Fighter shoots and kills enemy.

But the explosion never go away.

Explosion are Particle systems. They are prefabs.

When the player kills the enemy or both collide: I call this when killing the enemy, top of the call public GameObject explosion; public GameObject playerExplosion;

if ( other.gameObject.name.Contains("enemy") && other.gameObject.GetComponent().hp < 1 ) { Instantiate(explosion, other.gameObject.transform.position, other.gameObject.transform.rotation); explosion.name ="EnemyExplosion";

 Destroy( other.gameObject );
 Destroy( this.explosion,1 );
 }

I have tried Destroy(gameObject); Destroy(gameobject, 1); When I do this unity tells me quote Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy(Object, Single) DestroyOnContact:DestroyEnemy(GameObject) (at Assets/Scripts/DestroyOnContact.cs:63) HealthScript:Damage(Int32) (at Assets/Scripts/HealthScript.cs:64) HealthScript:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/HealthScript.cs:78) end quote

So I try using DestroyImmediate (theObject, true); it tell me to use Destroy.

I have tried Destroy(explosion); same thing unity tells me.

I tried to add the prefab of the explosion to the enemy or player object as a child hoping it would destroy but I cannot figure how to add it as a child.

So how do you in C# get rid of an instance of a prefab?

That's it

Thanks all

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
3
Best Answer

Answer by codestage · Jul 25, 2014 at 08:43 PM

 GameObject explosionInstance = (GameObject)Instantiate(explosion, other.gameObject.transform.position, other.gameObject.transform.rotation);
 Destroy(explosionInstance, 1);
Comment
Add comment · Show 4 · 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 Michellia · Jul 25, 2014 at 10:19 PM 0
Share

Thanks that worked. Does not make sense to me, bu tit works

more reading to do then....

not sure how to do the vote thingy

avatar image robertbu · Jul 25, 2014 at 10:20 PM 0
Share

If you question is answered, click on the checkmark to the left of the answer to close the question out and give the person who answered the question a bit of $$anonymous$$arma.

avatar image crunchyoverseas · Jul 25, 2014 at 11:31 PM 0
Share

They seriously need to rethink how $$anonymous$$arma and the point system works, people game it...

avatar image Michellia · Jul 26, 2014 at 01:22 PM 0
Share

Thanks I gave it the checkmark, cannot do the thumbs up, says I go not have 15 reputation, what ever that is.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Clone of rigid body prefab destruction if at certain position 3 Answers

Cannot Destroy Instanitaed prefab. 1 Answer

Destroying Instantiated Prefab 1 Answer

Destroying a instantiated prefab? 2 Answers

My prefab isn't getting destroyed 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