Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 SepM · Jul 04, 2015 at 02:41 PM · collidertriggertagreferencehitbox

Check Trigger Collision's Name/Tag

I'm making hitboxes for my game and as a simple test I want them to turn yellow whenever on hitbox touches another.

To start off, I created an onTriggerEnter function

 function OnTriggerEnter(collision : Collider){
     gameObject.renderer.material.color = Color.yellow;
 }

This works perfectly fine. If a hitBox touches a trigger, it turns yellow. But when I add an if statement that refers to the collision's game object, it doesn't work.

 function OnTriggerEnter(collision : Collider){
      if(collision.gameObject.name == "hitBox"){
         gameObject.renderer.material.color = Color.yellow;
     }
 }

I've tried different variations with "name", "tag", with and without "gameObject", but nothing happens. Is there something that I'm missing? Am I referencing the wrong thing? Any help is appreciated.

Comment
Add comment · Show 4
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 barbe63 · Jul 04, 2015 at 03:00 PM 1
Share

Do the collider belongs to the GameObject attached to it or is it a child? Also make sure they have kinematic rigidbodies.

avatar image lloydg · Jul 04, 2015 at 03:04 PM 0
Share

can you do a DebugLog(collision.gameObject.name) and see what it is printing, this might help you work out what is wrong. You should be able to see what you should be comparing it too.

avatar image meat5000 ♦ · Jul 04, 2015 at 03:07 PM 1
Share

CompareTag("Tag") works nicely.

If it doesnt work either, there is something wrong elsewhere; Like forgetting to check the isTrigger box on the Collider or forgetting to add a non-kinematic rigidbody somewhere.

avatar image peginet · Jul 04, 2015 at 03:54 PM 1
Share

kinematic rigidbodies working sloved my problem http://answers.unity3d.com/questions/1000365/unity5-c-ontriggerenter-not-working.html

1 Reply

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

Answer by SepM · Jul 09, 2015 at 05:05 PM

Thank you for your help, everyone! What solved my problem was adding a kinematic Rigidbody to my hit boxes. I realized that the reason why it had worked without the tag check was because they were touching other objects that happened to have their own Rigidbodies. I'm surprised I didn't even consider this. Now by adding Rigidbodies to the hit boxes, their collisions are finally registering. Thank you again!

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

25 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

Related Questions

Trigger can't see the enemy 2 Answers

Is it possible to detect which side of a sprite a touch came in from? 0 Answers

Reaching a gameobject from its collider 3 Answers

Use trigger with player but have a collider with everything else? 3 Answers

Script works for NPCs, but not Player 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