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 jason · May 18, 2010 at 07:20 AM · collisiondestroyparentchildtank

How do i kill an "enemy with character controller on + few child objects on"

Helor I'm trying to seek help with this question as previously i tried on various codes on destroying game objects once i collide with them, it works but not for my AI character with character controller and few childs on it. I wanted to test if the collision works for 1 hit kill before i add in GUI health textures for it.

But it seems like this script that i'm going to attach works on a small cube with box collider and with "is trigger" being ticked, but not towards my enemy. Hope someone can tell me another different way of coding it? or do i just need to tweak something else out of it?

I'm still new to Unity between and am eager to learn more from other people as well :) Thanks heaps!

Here's my code:

//var score = 0; var explosionPrefab : GameObject; //var explosionLife : float = 10; var Collider = CharacterController;

function OnTriggerEnter( other : Collider ) { if (other.tag == "Player") { //score += 5; print ("ENEMY BLOWN UP"); var expPos = other.transform.position; var exp : GameObject = Instantiate (explosionPrefab, expPos, Quaternion.identity); Destroy (other.gameObject); } }

Comment
Add comment · Show 4
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 StephanK · May 18, 2010 at 07:29 AM 0
Share

Could you specify what "is not working" means? Does it print the message? Are there leftover GameObjects? Is anything happening at all?

avatar image jason · May 18, 2010 at 08:20 AM 0
Share

sorry forgot to mention that. $$anonymous$$y enemy is not destroyed. yet it is still running around the area. Print message was not shown either.

what the enemy does is just continue attacking me.

avatar image BeB_Wir3 · Apr 02, 2013 at 10:21 AM 0
Share

i think you are trying to destroy the player. and you cant just destroy the player for data loss reasons. are there any errors?

avatar image AutoFredrik · Apr 07, 2013 at 10:50 AM 0
Share

Do you even have a trigger attached to the enemy? OnTriggerEnter can't be called without a trigger. It's obvious, but sometimes people forget :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cygon4 · Apr 07, 2013 at 10:58 AM

Hard to tell since it could be many things. Here's a list of what I think might be worth checking:

  • Have you double-checked the tag name, including upper/lowercase?

  • Is the enemy's collider on the same game object as your script (not on a parent of child)?

  • Is the Is Trigger property of the enemy's collider ticked?

  • Are both objects on Layers that are set to collide with each other in Unity's physics settings?

Also, I think @BeB_Wir3 is quite right, once you get it to work, it will try to destroy your player, not the enemy. That last line should be GameObject.Destroy(gameObject); (or this.gameObject if you want to be more explicit about were the property comes from).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Player object still gets destroyed even when shields up 1 Answer

Make a simple tree 1 Answer

How to detect child object collisions on parent 3 Answers

OnCollisionEnter not registering on children 0 Answers

Unparenting and then deleting a child part of a prefab, SOMETIMES child throws null reference exception? 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