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 awplays49 · Nov 16, 2014 at 05:26 PM · gameloadnotworking

Loading game forever?

I added this:

         if (Distance < MeetDistance)
     {
         FollowerState = FollowOrIdle.Following;
     }
     if (Distance > SeparateDistance)
     {
         FollowerState = FollowOrIdle.Idle;
     }
     while (FollowerState == FollowOrIdle.Following)
     {

to make the code say this:

     if (Distance < MeetDistance)
     {
         FollowerState = FollowOrIdle.Following;
     }
     if (Distance > SeparateDistance)
     {
         FollowerState = FollowOrIdle.Idle;
     }
     while (FollowerState == FollowOrIdle.Following)
     {
     if (Leader.rigidbody2D.transform.position.x > rigidbody2D.transform.position.x + GeneralDistance)
     {
         rigidbody2D.transform.position += Vector3.right * Speed * Time.deltaTime;
     }
     if (Leader.rigidbody2D.transform.position.x < rigidbody2D.transform.position.x - GeneralDistance)
     {
         rigidbody2D.transform.position += Vector3.left * Speed * Time.deltaTime;
     }
     if (Leader.rigidbody2D.transform.position.y > rigidbody2D.transform.position.y + GeneralDistance)
     {
         rigidbody2D.transform.position += Vector3.up * Speed * Time.deltaTime;
     }
     if (Leader.rigidbody2D.transform.position.y < rigidbody2D.transform.position.y - GeneralDistance)
     {
         rigidbody2D.transform.position += Vector3.down * Speed * Time.deltaTime;
         }
     }
 }

}

and now the game is loading forever. why?

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 awplays49 · Nov 16, 2014 at 05:20 PM 0
Share

the gameplay window loads forever when trying to play

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Nov 16, 2014 at 05:29 PM

Proper indentation would help make this readable and the problem more obvious. The issue is that you are do a while loop with this condition:

  FollowerState == FollowOrIdle.Following

...but nothing in the loop changes 'FollowerState', and you do not 'yield' in the loop, so control never goes anywhere else that could change 'FollowerState' to something besides 'FollowOrIdle.Following'. So you cycle in the loop forever hanging Unity.

Comment
Add comment · Show 3 · 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 awplays49 · Nov 16, 2014 at 05:33 PM 0
Share

i thought while meant "as long as () is true"

avatar image AlwaysSunny · Nov 16, 2014 at 05:34 PM 0
Share

It does, but it's true forever. The state never changes within your code. Please spend some time with the resource I shared in my answer. It will really help you, I promise!

avatar image awplays49 · Nov 16, 2014 at 05:55 PM 0
Share

Ok I will check it out

avatar image
0

Answer by AlwaysSunny · Nov 16, 2014 at 05:29 PM

Please consider dedicating some time to purposefully learning the C# language. It is your ad-hoc approach to learning that is giving you so many problems.

Please bookmark this great resource for learning C# basics very quickly. It's also a terrific reference: http://rbwhitaker.wikidot.com/c-sharp-tutorials

A while statement will execute until the condition becomes false. Since your while statement block never changes the state, it creates an infinite loop, causing Unity to hang.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Application.Quit not working?! 5 Answers

Compiled Game Crashing 1 Answer

Any idea why collision detection not working? [Video] 0 Answers

Save/Load Game and buttons New Game/Load Game? 1 Answer

Simple Code Not Working 4 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