Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 DrututtZ · Jun 29, 2021 at 03:48 PM · 2d gameenemycollider2dchildrenontriggerenter2d

How could i access to a specific collider box if it is in a children of the main Object? The script is in the main object.

Im making a 2D game so i want my enemy to receive damage when my player hits, the issue that i have is that i dont know how to call just the collider box that is in a children of the main objet(in this case the enemy), so it can "comparetag" with the weapon of my player.

I was trying with ontriggerenter2D the issue is that i dont know how to only access to the box colliders of a especific children because there are other children colliders that interfere in the process. Any one can help me pls? Here are the image references:

alt text

alt text

@Hellium

reference.jpg (14.8 kB)
replace-that.jpg (48.6 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 Devster2020 · Jun 29, 2021 at 04:12 PM 1
Share

Hi!
Forgive me, but it is difficult for me what you want to accomplish.
Does the "enemy" object have multiple children that have a collider as a component? If so, the script with the "OnTriggerEnter2D" or "OnColliderEnter2D" method must be added to the child you want to capture the action.
If the same script is placed on all children that have a collider, then each child will trigger the same piece of code.

Please explain better what you want to accomplish because the sentence is a bit confusing.

avatar image DrututtZ Devster2020 · Jun 29, 2021 at 07:13 PM 0
Share

yea thats what i mean, thnks i did it. The problem now is that i want to animate the enemy when its hitted but my animator controller is on the main object. How can i acces to it? Is there a command? the script does not recognize it

1 Reply

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

Answer by Nistroy · Jun 29, 2021 at 06:35 PM

Hi @DrututtZ ! Simply create a script in which there is the component.

Comment
Add comment · Show 4 · 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 DrututtZ · Jun 29, 2021 at 07:11 PM 0
Share

Okey, I tried that and it detects the collider. The problem now is that i want to animate the enemy when its hitted but my animator controller is on the main object. How can i acces to it? Is there a command? the script does not recognize it

avatar image Devster2020 DrututtZ · Jun 29, 2021 at 07:17 PM 2
Share

You need to access to parent of the collider.. write this into the "if" statement:
Animator animator = collision.transform.parent.GetComponent();

avatar image DrututtZ Devster2020 · Jun 29, 2021 at 07:34 PM 0
Share

Thanks dude! Now it works perfectly. I did not know the use of "parents"-

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.

Follow this Question

Answers Answers and Comments

167 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 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 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 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 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 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 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 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 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 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

OnTriggerEnter2D not working 2 Answers

Alternative OnTriggerEnter2D for class instances 0 Answers

How to get the position of a Tile my Player collided with using OnTriggerEnter2D? 0 Answers

Why is OnTriggerExit2D called before OnTriggerEnter2D? 1 Answer

OnTriggerEnter2D is called 2 more times in Melee combat system 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