• 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
Question by bpears · Jan 22, 2013 at 06:59 PM · javascriptontriggerstay

Does the -OnTriggerStay collider- script have to be child of collider triggering the function?

Or can you tell it, use a different objects collider as trigger?

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Loius · Jan 22, 2013 at 07:28 PM

No, it has to be on the object which is colliding.

You're free to send messages from the OnTriggerStay function to whatever objects need to know about the collision.

You can even call other OnTriggerStay functions if you need to for some reason, though that might get confusing.

Comment
bpears

People who like this

1 Show 2 · 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 bpears · Jan 22, 2013 at 07:50 PM 0
Share

How would you do this? if the message needs to be sent to component

avatar image Loius · Jan 22, 2013 at 08:08 PM 0
Share

Just call the function like any other function.

script.Function()

avatar image

Answer by aldonaletto · Jan 22, 2013 at 07:30 PM

I don't know if this is exactly what you're asking, but all OnTrigger events are sent to scripts attached to the trigger object and to the object that entered the trigger, not to their parents or children. If you have a script attached to object A and want to detect when something entered the trigger in a child of A, a simple solution is to use SendMessageUpwards to make the trigger call a function in its parent - add the code below to the child trigger script:

 function OnTriggerEnter(other: Collider){
   SendMessageUpwards("TriggerEntered", other);
 }

Define the function TriggerEntered(other) in the parent object's script:

 function TriggerEntered(other: Collider){
   // the collider "other" entered the child trigger
 }
Comment
bpears

People who like this

1 Show 2 · 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 bpears · Jan 22, 2013 at 07:54 PM 0
Share

I am trying to send message from item collider to player script, that it has entered that collider. Is this a built in function that I would not need to send a message? And maybe a way to say, ok, the player has entered the collider of certain objects collider? Trying to understand how it all works..

avatar image aldonaletto · Jan 22, 2013 at 10:00 PM 1
Share

If you want to send OnTrigger events to the player when he enters a trigger, just add the OnTrigger function to the player script, like this:

 function OnTriggerEnter(other: Collider){
   print("Player entered "+other.name);
 }

But the player must be a CharacterController or Rigidbody in order to be detected. If the player is a simple object with a collider, add a kinematic rigidbody to the trigger or to the player. Another hint: if the trigger moves, you must add a kinematic rigidbody to it, or it won't detect other colliders.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Multiple Cars not working 1 Answer

Damage rate HELP 1 Answer

how to use / simulate a using declaration in unityscript 1 Answer

Help converting C# to Unityscript 1 Answer

Why can I not drag and drop a gameobject into my script after declaring the variable in the script. 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