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 /
This question was closed May 21, 2016 at 09:23 PM by salrad for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by salrad · May 22, 2016 at 03:36 AM · unity 5collisioncollidercollider2d

Detecting collision of two game objects?

So I have an object with a collider attached to it and I made two colliders attached to the main camera (to stop the player from walking beyond the main camera boundaries) now I have a condition where the camera stops following the player when a certain object is on the screen and touching the collider on the left of the screen which is in this case the left boundary but I can't get to make this work I used this code:

 public class leftWallCheck : MonoBehaviour {
 
     private baby baby;
     // Use this for initialization
     void Start () 
     {
         baby = GameObject.FindGameObjectWithTag("Baby").GetComponent<baby>();
     }
 
     void OnCollisionEnter2D(Collision  col)
     {
         if(col.gameObject.tag == "Baby")
         {
             Debug.Log(baby.touchLeftWall.ToString());
             baby.touchLeftWall = true;
         }
     }
 
     void OnCollisionStay2D(Collision col)
     {
         if (col.gameObject.tag == "Baby")
         {
             Debug.Log(baby.touchLeftWall.ToString());
             baby.touchLeftWall = true;
         }
     }
 
     void OnCollisionExit2D(Collision col)
     {
         if (col.gameObject.tag == "Baby")
         {
             Debug.Log(baby.touchLeftWall.ToString());
             baby.touchLeftWall = false;
         }
     }
 
 }
 

this code attached to the left wall and "Baby" is the object I want the left wall to detect, but it is not working and the value of "touchLeftWall" is not changing

Comment
Add comment · Show 1
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 salrad · May 21, 2016 at 09:22 PM 0
Share

O$$anonymous$$ I feel stupid this is the second time it happens to me where I find the answer after posting the question but I figured it out I didn't know I had to attache rigidbody to the object :D thanks anyway

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Tilemap Collider 2D preventing objects from moving 2 Answers

How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer

How do I set an object's velocity to the velocity of an object that collided with it? 0 Answers

Disabling and Enabling a collision 1 Answer

Collision detection problem 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