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 /
avatar image
0
Question by UniluckStudios · Jul 16, 2017 at 08:52 PM · colliderdestroycollision detectioncollider2dclone

How to destroy a gameobject's clone when colliding with the ground?

Ok so in my game I have a spawner that spawns clones of a gameobject (Ball). I want the ball's clone to get destroyed when it impacts the ground. I have tried many times to make this work but I have not figured it out yet. Pls help.

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
0

Answer by Cornelis-de-Jager · Jul 16, 2017 at 09:18 PM

If you are copying an game object in the scene already it might cause problems. But if you are creating the clones from a Prefab in your asset folder then you can simply add the following code to a script on the clones objects:

 void OnCollisionEnter (Collision other) {
       Destroy (this.gameObject);
     }

If it is a trigger then use:

 void OnTriggerEnter (Collider other) {
   Destroy (this.gameObject);
 }
Comment
Add comment · Show 6 · 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 UniluckStudios · Jul 16, 2017 at 09:57 PM 0
Share

Ok I dont know how i would make a clone of something that is not in my game already. Sorry i am new at this. Here is my code for my spawner. How would i change it so that the spawner creates a clone of a prefab?

public class SpawnBallOn$$anonymous$$eyPress : $$anonymous$$onoBehaviour {

 public GameObject ball;
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.Get$$anonymous$$ouseButtonDown (0)) {
         Instantiate (ball, transform.position, Quaternion.identity);
     }
 }

}

avatar image UniluckStudios UniluckStudios · Jul 16, 2017 at 10:26 PM 0
Share

Ok i figured out how to make the ball a prefab and add it to my script. I have also done the code that should destroy the object but it won't work. I did a debug to see if the collision was even registered and it apparently wasnt.

avatar image UniluckStudios · Jul 16, 2017 at 10:08 PM 0
Share

Ok i have figured out what to do. Thank you for the help.

avatar image UniluckStudios · Jul 16, 2017 at 10:27 PM 0
Share

Ok i figured out how to make the ball a prefab and add it to my script. I have also done the code that should destroy the object but it won't work. I did a debug to see if the collision was even registered and it apparently wasnt.

avatar image Cornelis-de-Jager UniluckStudios · Jul 16, 2017 at 10:47 PM 0
Share

$$anonymous$$ake sure of the following:

  • Your object has a Collider Script.

  • Ensure that the Trigger Option is Disabled (i.e. not a Trigger) see this link for explination

If you need it as a trigger, however, then use the following code ins$$anonymous$$d:

 OnTriggerEnter (Collider other) {
  Destroy (this.gameObject);
 }


avatar image chadkiernan · Aug 30, 2018 at 12:13 AM 0
Share

Thank YOu!!! I have been trying to figure this out for hours! Everyone has been saying to attach a script to the player and nothing was working. This, first try, BA$$anonymous$$!

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

85 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 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 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 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

OnCollisionEnter is not working for me!! 1 Answer

Platform Collider Not Working When Enemy Collides With It 1 Answer

OnTriggerEnter2D being called by GameObject without the trigger 1 Answer

Objects falling through EdgeCollider2D on the ground 0 Answers

Player colliding with object then destroying/killing Player 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