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
-1
Question by kawales · Dec 27, 2014 at 09:56 PM · c#2dfreezeground

My game frozzes when I use a while to check if there's colision

Ok so I'm still having the problem whit the jump scrip([last post][1]) so I almost fixed it but now when I press my UI button for it my unit frizzes and I have to launch it up again! Heres my Code:

 public void GroundCheck(Collider2D coll){
 
                                 // ground is self explained I hope...
                 while (coll.gameObject.name == "ground") {
             
                         rigidbody2D.velocity = transform.up * 15;
                         
                         
                 
                         }
                 
                     
 
 
 
   [1]: http://answers.unity3d.com/questions/862880/disable-jumping-more-than-once.html




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 screenname_taken · Dec 27, 2014 at 10:05 PM 0
Share

You don't have an exit check. You haven't included a condition check or a way to exit the while loop and that is why it locks in there. That object's name is always ground, so it never gets out of the loop. Try to use an if check on a CollisionStay or TriggerStay function ins$$anonymous$$d.

2 Replies

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

Answer by Thom Denick · Dec 27, 2014 at 10:02 PM

There's no exit for your while loop. This will cause Unity to freeze. Use "Update" instead of while loops.

Comment
Add comment · Show 1 · 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
avatar image kawales · Dec 28, 2014 at 09:33 AM 0
Share

Ah ok srry I'm still really new to Unity

avatar image
0

Answer by LewiksR · Dec 28, 2014 at 10:34 AM

Use this instead

 void OnCollisionEnter2D (Collider2D col) {
      //code here
 }
Comment
Add comment · Show 2 · 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
avatar image kawales · Dec 28, 2014 at 11:46 AM 0
Share

@LewiksR Did that but off topic when i click my UI he jumps normally but even if hes not touching the ground he can still jump in air... here's what I did:

  1. public void OnCollisionEnter2D(Collider2D col) { if (col.gameObject.name == "ground") { rigidbody2D.velocity = transform.up

    • 15; } }

avatar image LewiksR · Dec 28, 2014 at 01:52 PM 0
Share

That's why i commented "//code here"

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

29 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Ground Detection Lagging - 2D 2 Answers

Sprite Sheet animation without fancy add-ons 1 Answer

if it's you, how will you solve it ? 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