• 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 frankyboy450 · Oct 07, 2013 at 05:14 PM · gameobjectdestroyother

Problem with destroying other upon collision

Hi. I made an object called "DestroyerOfWorlds" that follows my player who runs on a platform in 2D. when an object enters the "DestroyerOfWorlds" it should be deleted. so I made this script.

 using UnityEngine;
 using System.Collections;
 
 public class DeleteFloors : MonoBehaviour {
     
     public bool obliverate = false;
     
     void OnTriggerEnter(Collider other) {
         if(obliverate == true)
         {
             Destroy(other.gameObject);
         }
     }
 }


The "IsTrigger" is set to true but the problem is that when something with a collider enters the "DestroyerOfWorlds" nothing happens... I tried putting this line

Destroy(other.gameObject);

Inside my character and it works fine, whenever he passes through something with a collider. it gets destroyed. but not with the "DestroyerOfWorlds"

Does anyone know if I've done anything wrong?

Thanks. -Frank

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 clunk47 · Oct 07, 2013 at 06:08 PM

Have you tried debugging to be sure obliverate is true? Also, be sure that one of the objects involved is a non-kinematic rigidbody, and that your trigger object has (Is Trigger) checked either in the editor, or via script.

 using UnityEngine;
 using System.Collections;
 
 public class DeleteFloors : MonoBehaviour 
 {
     public bool obliverate = false;
     
     void Awake()
     {
         if(!collider.isTrigger)    
             collider.isTrigger = true;
     }
     
     void OnTriggerEnter(Collider other) 
     {
         if(obliverate)
         {
             Destroy(other.gameObject);
         }
         print (obliverate);
     }
 }
Comment
Add comment · Show 8 · 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 frankyboy450 · Oct 07, 2013 at 08:06 PM 0
Share

I tried this but there's still nothing happening. I'm trying to use this for when the object leave the camera view (which is Orthographic) do you think I can use another way to do this?

I added the script to my character which runs into some objects with "Is Trigger" set to true, and they get removed...

avatar image clunk47 · Oct 07, 2013 at 08:17 PM 0
Share

So this character... is it a Rigidbody, or CharacterController? If the latter, have a look at OnControllerColliderHit.

avatar image frankyboy450 · Oct 07, 2013 at 08:51 PM 0
Share

Yes. the character has a CharacterController attached to him, but I have a cube as a child to the character that follows the player and is supposed to destroy the floor that get's out of view. the cube has a "Box Collider" attached

avatar image clunk47 · Oct 07, 2013 at 09:06 PM 0
Share

I'm guessing you want that cube to be the trigger, so make sure isTrigger is checked and you have the script attached to that cube, not your character. Remember either that cube or the floors needs to be a rigidbody.

avatar image frankyboy450 · Oct 08, 2013 at 03:58 PM 1
Share

Thanks for the help :)

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Destroy object when transform.position.x > 10. 1 Answer

Destroy(gameObject) does not work 2 Answers

Placing a cube on the face of another 4 Answers

Collision Detection for a Prefab? 3 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