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 ILoveMyDada · Feb 06, 2018 at 09:31 AM · mousepositionboxcollider2dontriggerenter2ddebug.log

OnTriggerEnter2D not working at all

Hi so what I have here is a Cube object (percentCollider) that has an isTrigger on its Box Collider. And the object that is going to move into it is also a Cube object (DrawingCircleCollider) that is being moved around by the mouse, has a Rigid Body. So that when I move the mouse it can trigger a count to go down in value. Problem is that it doesn't work at all. The first Debug doesn't even show up. I've been able to make something like this work many times but for some reason I'm lost on this.

Any help would be appreciated!

 public GameObject drawingCircleCollider;
 public Text percentageText;
 public int count;


 void Start()
 {
     count = 100;
     SetCountText (); 
 }

 void OnTriggerEnter2D (Collider2D percentCollider)
 {
     Debug.Log ("WORKING");

     if (percentCollider.CompareTag ("DrawingCircleCollider")) 
     {
         count = count - 1;
         SetCountText ();

         Debug.Log ("COUNT OK");
     }
 }

 public void SetCountText()
 {
     percentageText.text = "" + count.ToString () + "%";
 }
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 Mehul-Rughani · Feb 06, 2018 at 10:09 AM 0
Share

Hello, Have you used BoxCollider2D in unity ?

if you have 3D objects(with 3D collider and rigidbody) then you need to use OnTriggerEnter(Collider collider) method

if you have 2D objects (with 2d Collider and Rigidbody2D) then you need to use OnTriggerEnter2D(Collider2D collider)

Hope it will help you

avatar image ILoveMyDada Mehul-Rughani · Feb 06, 2018 at 10:20 AM 0
Share

Hey yeah so I have a BoxCollider2D on the trigger and I have a RigidBody2D on the object that would move through the trigger. Still doesn't work. The script is attached to the trigger object by the way.

Thanks for the reply

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ILoveMyDada · Feb 06, 2018 at 10:50 AM

Never mind I got it to work by just doing away with 2D in general and just switched to 3D. That seemed to work fine.

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

75 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 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 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

BoxCollider error from C# to UnityScript 0 Answers

Why is this only working for the second object that collides? 1 Answer

Boxcollider2D, Trigger not working 2 Answers

The current score variable not updating when an enemy is hit (Using OnTriggerEnter2D function),Counter for current score not working with OnTriggerEnter2D function. 1 Answer

Why is my 2D Collision Delaying or Missing? 0 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