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 /
avatar image
0
Question by Slopius · Aug 21, 2011 at 06:29 PM · ontriggerenterparentchild

Update a parent owned Script from within a child script

So I want to make it so that I can update the Parent's Target Script based on 2 Child scripts.

Basically I want it so that if they are within the First Sphere Collider, the OnTriggerEnter event fires and updates the Target to point at the Hero.

I have a Child script that just has an OnTriggerEnter() where it checks if the object is a Hero and then if it is, change the Target to go to it.

I've attached this script to the Enemy object, so the Enemy is the Parent, the Child is this script.

The OnTriggerEnter part of the script just doesn't seem to get called ever, can anyone tell me what I'm doing wrong here?

 void OnTriggerEnter(Collider other) {
         Debug.Log("Has Entered OnTriggerEnter");
     if(other.gameObject.layer == LayerMask.NameToLayer("Hero"))
     {
             
         transform.parent.gameObject.GetComponent<SteerForTarget>().Target = other.gameObject.transform;

         
     }
 }
 

Enemy and Hero both have Rigidbody's the GameObject that is attached to Enemy just has a Sphere Collider with the OnTrigger box ticked and my Aggro code, which you see below.

Also i'm using Unity Steer to move the characters around.

Thanks!

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 daniellasry · Aug 22, 2011 at 05:26 PM 0
Share

Have you checked your collider's "isTrigger" field?

http://unity3d.com/support/documentation/Components/class-SphereCollider.html

avatar image Talimar · Aug 24, 2011 at 04:22 AM 0
Share

Do both objects have sphere colliders or only 1?

0 Replies

· Add your reply
  • Sort: 

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

Make a simple tree 1 Answer

Becoming parent after OnTriggerStay/Enter? 1 Answer

OnTriggerEnter not being called with multiple colliders 1 Answer

Detection OnTriggerEnter on the Child in Parent script. 2 Answers

Parenting On Trigger not Working? 3 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