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 laskiapina2 · Mar 28, 2012 at 06:01 PM · collidertriggerchild

How to get info from child triggers?

I have a parent and it has a script and three childs with colliders that are triggers. How can I get info about the child triggers colliding with other objects by name?

For example OnTriggerEnter(child's name). That's not how you would write it, but I hope it's more clear what I want to do.

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

Answer by Owen-Reynolds · Mar 28, 2012 at 10:05 PM

There might be a good way, but I've just been writing a script for the child and having it tell the parent. Ex:

 // In parent:
 // NOTE: child triggers will call us here:
 void public handleTrigger(int whichTrigger, Collider cc) { ... }

   
 // Generic child trigger script:
 public int trigNum = 0; // set to 0, 1, 2 ... for each child trigger 

 void OnTriggerEnter(Collider cc) {
     // pass it along to the parent:
     transform.parent.GetComponent<parentScriptName>().handleTrigger(trigNum, cc);
 }

Actually, I wrote two nearly identical scripts (they call different parent functions.) If I was thinking, I'd have combined them into one, like above.

Comment
Add comment · Show 3 · 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 laskiapina2 · Mar 29, 2012 at 05:10 AM 0
Share

I understand what that would do, but can't seem to get it to work. I'm not familiar with "cc" and does "..." mean in that you write your code in that? I'm trying to learn Javascript.

avatar image laskiapina2 · Mar 29, 2012 at 08:39 AM 0
Share

I got it to acknowledge the child colliders by using this:

private var canYouWalkRight = true; var rightWall : GameObject; rightWall = GameObject.Find("rightWallCollider"); function OnTriggerEnter(Collider) { if (rightWall.collider) canYouWalkRight = false;}

But how can I tell it canYouWalkRight is true?

avatar image Owen-Reynolds · Mar 29, 2012 at 02:05 PM 0
Share

Ah...my suggestion is C#. cc is just the name I picked for the variable. Not important.

The idea is, if you want to know which thing hit (and I think you have to do it like this for triggers) you need a separate script for the kids, which detects the hit and "talks to" the parent. You can look up how one script talks to another (in JS it's a little different, but easy to find.)

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

Controller Collider Script 1 Answer

Extracting child trigger from compound collision 0 Answers

Detect if out of trigger 2 Answers

Action activates trigger. 1 Answer

Can't click gameobject when over another trigger? 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