• 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 cstabile18 · Mar 18, 2014 at 04:46 PM · triggerontriggerenterontriggerenter2d

What am i doing wrong, OnTriggerEnter2D?

I have one game object (with a box collider 2d component and is trigger checked on) that moves with user input. I then have another game object with tag Divider that is stationary and also has a box collider 2d component but without is trigger on. When the two collide, I want limitX to be set to true. However, for some reason it seems the two are not colliding at all. The console does not run anything when I run the game and make the two collide. I have tried all combinations of is trigger being on or off for the game objects and some other things as well but I can't seem to get it to work. Help?

 void OnTriggerEnter2D(Collider2D collider) {
         Debug.Log ("Triggered: " + collider.name); 
 
         if (collider.tag == "Divider") {
             limitX = true;    
         }
 
     }
Comment
Add comment · Show 3
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 MousePods · Mar 18, 2014 at 04:50 PM 0
Share

I think one of the objects has to have a rigidbody on it if I am not mistaken.

avatar image koray1396 · Mar 18, 2014 at 04:57 PM 0
Share

You should be turning off trigger of the collider attached to the object that moves, and you should be turning on trigger in the other collider.

avatar image cstabile18 · Mar 18, 2014 at 05:06 PM 0
Share

the rigid body did it, thanks!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 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

Related Questions

Ontriggerstay2d only runs 26 times in a row? 3 Answers

OnTriggerEnter2D not working, alternatives? 2 Answers

Collision problem in C# 4 Answers

Colliding two GameObjects 1 Answer

Can't figure out how to use multiple triggers in single scene 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges