Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Sera_GU · Feb 10, 2016 at 01:54 PM · destroyclone

Destroy not working and weird behaviors ( multiple clones )

Hi everybody,

I recently started to use Unity and i'm facing few problems. I want to create something that'll behave like a mine, thus means there would be an object and when someone will step on it, an explosion will occurs and the object that stepped on will take damage. This part works great, i've been able to figure out this behavior by myself.

After stepping on a mine, the object properly destroy itself. Therefore the "explosion" it creates remains here. Even more weird, the mine create multiple clone of this explosion. Here's the code

 using UnityEngine;
 using System.Collections;
 
 public class Mine : MonoBehaviour {
     
     Transform playerT;
     GameObject itself;
     
     // Use this for initialization
     void  Awake() {
         playerT = GameObject.FindGameObjectWithTag ("Player").transform;
     }
 
 
     void OnTriggerEnter(Collider other) 
     {
         if (other.gameObject.tag == "Monster") {
 
             EnemyHealth enemyHeatlh = other.GetComponent<EnemyHealth> ();
             enemyHeatlh.Death ();
 
             PyroExplode Pyro = gameObject.AddComponent("PyroExplode") as PyroExplode;
 
             Pyro.setTransform(transform);
             Pyro.Generate ();
 
             Destroy (Pyro.gameObject, 1.6f);
             Destroy (this.gameObject, 1.6f);
 
         }
     }
 }

In this code, i instantiate a new PyroExplode, set its transform attribute and call the methode Generate() on him. This is the Generate() method :

 public void Generate(){    
     Instantiate ( Resources.Load ("Pyro1"), mineTransform.position, mineTransform.rotation);
 }

Which will load a prefab with an animation, sphere collider and script attached to it ( the script is rendering the explosion effect ). So now this is what happens when someone step on a mine alt text

Multiples clones are created. I first thought it was because monsters were still colliding with the mine, thus recalling the OnTriggerEnter() event. I've tried to set the radius of my collider to 0 in my OnTriggerEnter() so it wouldnt collide with anything else anymore, but it doesn't help. Also, as you can see, the Pyro doesn't get destroyed. I've tried to call Destroy inside the PyroExplode class to see if it would make a difference but it doesnt.

So here are my 2 questions : 1- Why doesnt it get destroyed ? 2- Why is there more than 1 Pyro when something step on a mine ?

pyro.png (1.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

Not being able to destroy clone of prefab. 0 Answers

Delete gameobject clone after a new one spawnes. 2 Answers

Destroy the first instantiated clone after 4 have been instantiated 1 Answer

Desroy clone 1 Answer

destroy asset is not permitted to avoid data loss? 0 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