Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 cstabile18 · May 09, 2014 at 03:26 AM · bugbugs

Unity bug - detecting a collision that doesn't occur?

So I have 3 sprites: 1.) a ball with a Rigid Body 2D, a Box Collider 2D, and tag "Ball" 2.) a transparent grey square with a Box Collider 2D (Is Trigger) and tag "Area" 3.) a green rectangle with a Box Collider 2D and tag "Ground". A script called BallMovement is attached to the ball. The script uses the following code to toggle a boolean "inContact" between true and false:

 void OnTriggerEnter2D (Collider2D other) {
 
         if (other.gameObject.tag == "Area") {
         
             inContact = true;
 
         }
     }
 
     void OnTriggerExit2D (Collider2D other) {
         
         if (other.gameObject.tag == "Area") {
             
             inContact = false;
             
         }
     }

At start, the ball falls from the top of the screen and, when it comes in contact with the grey square the user must press the spacebar. If the user presses the spacebar at the same time that inContact == true then a force is applied to the ball to make it move upward. On its way back down, the user will again have to hit spacebar to keep the ball in the air. If he fails to do this, the ball will fall down towards the ground. Using the following code, the script detects the collision between the ball and the ground and toggles a boolean called "miss" between true and false:

 void OnCollisionEnter2D (Collision2D collision) {
 
         if (collision.gameObject.tag == "Ground") {
                 
             miss = true;
 
         }
     }

Another script called GameManager checks to see if miss == true and, if so, runs the following code to end the game and displayed the main menu screen:

 void Update () {
 
         if (BananaMovement.miss) {
 
             Application.LoadLevel(0);
 
             BananaMovement.miss = false;
         }
     }

For some reason, even when the ball is clearly not in contact with the ground (even when at the complete opposite end of the screen) the game will end and the main menu screen will be loaded. When I set it up so that the ball would automatically move back upward when coming in contact with the grey square (no user input needed), it would run fine with no interruption HOWEVER if I clicked on something in the inspector or if I clicked Stats to see my FPS while it was running it would sometimes quit out for no reason. I have checked my code over and over and I am 100% sure there is nothing in my code that would cause this to happen. Is this a bug in Unity?

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 robertbu · May 09, 2014 at 03:28 AM 0
Share

You don't provide enough of your scripts for anyone to see if your logic is sound. If the 1000s of questions I've been involved in, only one was a Unity bug. So the odds are against you, but not impossible. Is there anything in the log file?

avatar image cstabile18 · May 09, 2014 at 03:45 PM 0
Share

No, nothing in the log file

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.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Need help: Replay have bug... 0 Answers

Error while using Time.deltaTime 2 Answers

Why does all my information in Unity dissappear 0 Answers

multiple shaders per shader file 2 Answers

Strange unity 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