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
-3
Question by maroonrs2 · Apr 19, 2012 at 08:13 PM · collisioninstantiatecolliderdestroyshooting

Destroy() not working on collision

Here is my script:

 function Update()
 {
     transform.position += transform.up * 20 * Time.deltaTime;
 }
 function OnTriggerEnter(other : Collider)
 {
     if(other.gameObject.CompareTag("Enemy"))
     {
         Destroy(gameObject);
     }    
 }

I do not have the slightest clue. I tried changing tags. They both have rigidbodies. Im shooting a prefrab at it with this:

 var bullet:Transform;
 
 function Update()
 {
     if(Input.GetMouseButtonDown(0))
     {
         clone = Instantiate(bullet, transform.position , transform.rotation);
         Destroy(clone.gameObject,2.0f);
     }
 }

They both have colliders and rigidbodies. I made sure everything was in place like the tag of enemy and stuff.

Comment
Add comment · Show 6
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 maroonrs2 · Apr 19, 2012 at 08:24 PM 0
Share

wow omg why are noobs -1ing this?

avatar image kevork · Apr 19, 2012 at 08:31 PM 0
Share

It isn't very clear what you are asking for help with. Is the OnTriggerEnter being called? If so, is the tag properly set to Enemy? I doubt you have the bullet tagged with "Enemy" which is what it would need to be tagged with assu$$anonymous$$g the above script is attached to the object that you want to be destroyed when it collides with a bullet.

avatar image Piflik · Apr 19, 2012 at 08:32 PM 0
Share

He probably wants to destroy the bullet, though.

avatar image kevork · Apr 19, 2012 at 08:41 PM 0
Share

Unfortunately it isn't very clear what is the problem or what is the expected outcome, which is likely why the initial question was downvoted.

avatar image maroonrs2 · Apr 19, 2012 at 08:57 PM 0
Share

kevork doesnt know what he is talking about. Yes i want to destroy the bullet too but havn't got there yet. I found out the problem. Active Is Trigger on both of them xD

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Piflik · Apr 19, 2012 at 08:25 PM

Have you checked the 'Is Trigger' option in the colliders?

Your code is good, methinks.

Comment
Add comment · Show 3 · 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 maroonrs2 · Apr 19, 2012 at 08:29 PM 0
Share

no? what for?

avatar image Piflik · Apr 19, 2012 at 08:31 PM 1
Share

OnTriggerEnter needs Triggers, OnCollisionEnter needs Colliders that are not Triggers.

avatar image maroonrs2 · Apr 19, 2012 at 08:57 PM 0
Share

i didnt read ur answer to my comment question above. I figured it out the hard way xD

avatar image
1

Answer by rutter · Apr 19, 2012 at 08:27 PM

Are you sure that all of these functions are being called? You might try a few distinctive `Debug.Log()` calls to watch your code's execution -- say, log each time you create a bullet, each time the bullet hits something, each time you try to destroy the bullet, and so on.

Check what actually happens against your expectations, and you should have a better idea of what's going wrong.

You could check the script reference for `OnTriggerEnter()` and make sure that you have things set up right. You mention that both objects have rigidbodies attached. Do they have colliders? What layer are those colliders on? Is one or more of the colliders a trigger?

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

Instantiate 1 object after 2 objects collide. ( C# ) 1 Answer

Destroying object when player walks over it 1 Answer

How to destroy an instantiated prefab object and keep instantiating it 1 Answer

destroy instantiated game object on collision with another game object 1 Answer

Collision Problem 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