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
0
Question by Bootsgaloore · Aug 20, 2012 at 12:16 PM · objectdestroytouchesdissapear

Destroy an enemy when it touches an object

hi im stuck and im wondering if anyone could help.

im absolutely useless with script .. i need and object to dissapear when it touches an object

Thanks

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

2 Replies

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

Answer by Khada · Aug 20, 2012 at 12:26 PM

Easy. Wherever it is that you detect the collision, put this:

 GameObject.Destroy(enemyGameObject);

If you're using the OnCollision method, you can get the object via Collision.gameObject

EDIT:

Haven't checked the code but this should work.

 function OnTriggerEnter (other : Collider) 
 { 
     if (other.CompareTag ("Player")) 
     { 
         other.transform.position = destination.transform.position; 
     }
     else //must be enemy
     {
         GameObject.Destroy(other.gameObject);
     }
 }

Highly suggest you go learn the basics of programming. You'll have a very hard time making a game without some fundamental knowledge.

Comment
Add comment · Show 19 · 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 Bootsgaloore · Aug 20, 2012 at 12:40 PM 0
Share

i got an error can you be more specific please (BCE0005: $$anonymous$$ identifier: 'enemyGameObject'.)

avatar image Khada · Aug 20, 2012 at 12:43 PM 0
Share

'enemyGameObject' needs to be replaced with whichever game object is your enemy. How you do this depends on the context. I would need much more detail to tell you exactly how to do it for your situation.

avatar image Bootsgaloore · Aug 20, 2012 at 12:45 PM 0
Share

Im planning on knocking this object off to a teleporter .. but i also use this script to teleport the player ... heres the script

JS

var destination : Transform;

function OnTriggerEnter (other : Collider) { if (other.CompareTag ("Player")) { other.transform.position = destination.transform.position; } }

avatar image tigerfoot · Aug 20, 2012 at 01:14 PM 1
Share

You got errors? What error? Tell us what error is popping up.

avatar image tigerfoot · Aug 20, 2012 at 01:24 PM 1
Share

If it didnt print anything the collision never occurs. Do you have a rigidbody attached to one of the colliding objects?

Quote from Unity Docs: "... trigger events are only sent if one of the colliders also has a rigidbody attached."

Show more comments
avatar image
0

Answer by jordo834 · Aug 20, 2012 at 01:30 PM

What script are you using to detect the collision? You should use the Collision or RayCastHit or whatever youre using, normally called "hit" to get the enemy gameobject, so try replacing enemyGameObject with hit.gameObject

Comment
Add comment · Show 1 · 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 tigerfoot · Aug 20, 2012 at 01:34 PM 1
Share

It doesnt matter. That function "OnTriggerEnter" is never called because the collision is not registered. The problem is somewhere else. Perhaps he didnt attach rigidbody component to neither object

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

10 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

Related Questions

Can't destroy a script. 1 Answer

How can I access a variable from another script in a separate object? 1 Answer

How to disable an object 1 Answer

Material has been destroyed 1 Answer

Destroy object using mouse click(raycast to detect collision) 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