Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 napi15 · Mar 28, 2017 at 07:18 AM · gameobjectprefabridigbodyunity 5.1

How to destroy a gameObject only when inside a rigidBody

Hello ,

I'm trying to make a rythm music game, where notes in shape of sphere will drop down on a table and once user hit the correct key(1 to 6) , I want the correct note to explode depends on which rail is the note , So my logic goes like this :

As you can see I have an invisible rigid body , so while the note is inside of it , if user hit the correct key , I wanted the note to explode

alt text

and my note Control script goes like this :

     void Update () {
         if (Input.GetKeyDown(activate))
         {
             if (score)
             {
 
                 Debug.Log(gameObject.name);
                 Destroy(gameObject);
 
                 Instantiate(succBurst, transform.position, succBurst.rotation);
                 score = false;
             }
 
         }
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         
         Debug.Log(other.gameObject.name);
 
 
         if (other.gameObject.name == "FailedCol")
         {
             Destroy(gameObject);
       
             Instantiate(failedBurst, transform.position, failedBurst.rotation);
         }
 
        if( (other.gameObject.name == "score1"))
         {
 //The Ballon is inside the scoring rigid body which is the invisible part on picture 
                 score = true; 
                
             }
     
     
         }
     
     }

But it seems not to work properly , how to destroy the gameObject ( the note ) prefab Only when inside the rigid body? What is wrong with my code and what I have missed?

Thank you

untitled.png (377.8 kB)
Comment
Add comment · Show 2
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 dvandamme · Mar 28, 2017 at 07:36 AM 0
Share

Destroy(other.gameObject);

avatar image beStrange · Mar 29, 2017 at 12:18 AM 0
Share

To be honest, your particular case is probably better off in the forums. I can already see a few other problems with your current approach, that would exceed the scope of the answer system.

For example you should use an object pool, and reuse game objects, ins$$anonymous$$d of creating/destroying them in mass. Otherwise you'll end up with major performance issues, since the garbage collector has to work in overtime, cleaning up all those notes and particle systems.

I wont go into more detail here, but i hope i'll see you on the forums, where we can help you in a much better environment.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by shadowpuppet · Mar 28, 2017 at 08:11 PM

I am no expert ( putting it mildly) so not sure I understand the setup. If I were to attempt this project what you have as a rigidbody on he rail I would have be a triggerzone(with your script on it) and the rigidbody and collider on the dropping note. SO when the note enters the triggerzone and the correct key pressed the corresponding prefab instantiates

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help? Im trying to get my zombie prefab to spawn, but stop them spawning after a set spawn limit. 1 Answer

Reinitialize prefab 0 Answers

How to save/load references to components and prefabs 1 Answer

Determine if game object is tyoepf One Prefab 3 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