Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Dod_Mason · Aug 14, 2016 at 08:32 AM · triggerobjectchild

how should i call or summon my child...

Hi guys really nice to meet yall :3

ok.

I got a character and it has a child object (invisible trigger collider). the child is like attack box or attack range. if something nasty is in that area of box (IN RANGE), player character will stop moving and swing his axe like maniac.

so i used OnTriggerStay2D on player character script to detect enemy.

     void OnTriggerStay2D(Collider2D collider)
     {
         if (collider.gameObject == Target)
         {
             Debug.Log("Swinging AXE >:0");
         }
     }

and it worked fine! but as you can see i didn't use THAT child object. instead, i just made secondary trigger collider on player character. because i don't know how to call or summon child or other external object to the script and apply it to OnTriggerStay2D method...

so noob q_q.

can you teach me how to call child (or out side object) and apply to OnTriggerStay2D method?

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

1 Reply

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

Answer by G4merSylver · Aug 14, 2016 at 09:47 AM

MonoBehaviour.OnEnterTrigger(); - I am quoting from the Script Reference, "Sent when another object enters a trigger collider attached to this object (2D physics only)." meaning, if you want to use it as a child you have to write a script just for the child object, then you can just return a boolean to your parent script. You can simply get the value by making a reference or using GetComponent.

Another alternative would be using Physics2D.OverlapCircle - which would completely eleminate the need for the child collider.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

What is the best way to script a trigger that moves a object from point a to point b in C# (unity 5) 0 Answers

Enable Multiple Box Collides From Parent Object 2 Answers

What is the best way to script a trigger that moves a object from point a to point b in C# (unity 5) 1 Answer

OnTriggerEnter2D() does not work !!! 0 Answers

How do I make an object that only passes through certain objects? 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