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 trollzor4674 · Jan 09, 2020 at 02:05 PM · crashinglong

Unity keeps crashing and I dont know why

So I'm fairly new to using Unity so I don't know everything about it. The problem is that Unity keeps crashing for no reason and I wanted to ask if some of u can get behind my promblem. This is the part of my Code thats causing the Problem (I think...) Its very long and probably really bad but like I said I can't really pinpoint the reason unity keeps crashing. (The Code is for an Enemy in a Turn Based Combat (kinda like DnD) and it normally keeps chrashing on the Turn right brfore the Enemy gets close enough to the player to Attack)

void Update() { if (Leben <= 0) Die();

     if (Turn == true)
     {
         if (CheckPlayerProx() == 1)
             closeProx= true;
         else
             closeProx= false;

         if CheckClose() == 1)
             close= true;
         else
             close= false;


     }
 }

 void CheckMove()
 {
     rechts = 0;
     links = 0;
     oben = 0;
     unten = 0;

     while (Movement > 0 && closeVal== false)
     {
         if (XGegen - 1 > XWert)
         {
             Movement--;
             XWert++;
             rechts++;
         }

         if (XGegen + 1 < XWert)
         {
             Movement--;
             XWert--;
             links++;
         }

         if (YGegen - 1 > YWert)
         {
             Movement--;
             YWert++;
             oben++;
         }

         if (YGegen + 1 < YWert)
         {
             Movement--;
             YWert--;
             unten++;
         }


         if (XWert == XGegen + 1 && YWert == YGegen - 1)
         {
             int ur = Mathf.RoundToInt(Random.Range(1f, 2f));
             if (ur == 1)
             {
                 Movement--;
                 YWert++;
                 oben++;
             }
             else
             {
                 Movement--;
                 XWert--;
                 links++;
             }
         }
         else
         {
             if (XWert == XGegen - 1 && YWert == YGegen - 1)
             {
                 int ul = Mathf.RoundToInt(Random.Range(1f, 2f));
                 if (ul == 1)
                 {
                     Movement--;
                     YWert++;
                     oben++;
                 }
                 else
                 {
                     Movement--;
                     XWert++;
                     rechts++;
                 }
             }
             else
             {
                 if (XWert == XGegen + 1 && YWert == YGegen + 1)
                 {
                     int or = Mathf.RoundToInt(Random.Range(1f, 2f));
                     if (or == 1)
                     {
                         Movement--;
                         YWert--;
                         unten++;
                     }
                     else
                     {
                         Movement--;
                         XWert--;
                         links++;
                     }
                 }
                 else
                 {
                     if (XWert == XGegen - 1 && YWert == YGegen + 1)
                     {
                         int ol = Mathf.RoundToInt(Random.Range(1f, 2f));
                         if (ol == 1)
                         {
                             Movement--;
                             YWert--;
                             unten++;
                         }
                         else
                         {
                             Movement--;
                             XWert++;
                             rechts++;
                         }
                     }
                 }
             }
         }
     }

     Moving();
 }

 void Moving()
 {
     if (rechts > 0)
         StartCoroutine(MoveRight());
     else
         if (links > 0)
             StartCoroutine(MoveLeft());
         else
             if (oben > 0)
                 StartCoroutine(MoveUp());
             else
                 if (unten > 0)
                     StartCoroutine(MoveDown());
                 else
                     Moving();
 }
 IEnumerator MoveRight()
 {
     rechts--;
     Geh--;
     yield return new WaitForSeconds(0.3f);
     transform.Translate(50f, 0f, 0f);
     X++;
     if (Geh > 0 && close== false)
         Moving();
     else
         CheckAngriff();
 }

 IEnumerator MoveLeft()
 {
     links--;
     Geh--;
     yield return new WaitForSeconds(0.3f);
     transform.Translate(-50f, 0f, 0f);
     X--;
     if (Geh > 0 && close== false)
         Moving();
     else
         CheckAngriff();
 }

 IEnumerator MoveUp()
 {
     oben--;
     Geh--;
     yield return new WaitForSeconds(0.3f);
     transform.Translate(0f, 50f, 0f);
     Y++;
     if (Geh > 0 && close== false)
         Moving();
     else
        CheckAngriff();
 }

 IEnumerator MoveDown()
 {
     unten--;
     Geh--;
     yield return new WaitForSeconds(0.3f);
     transform.Translate(0f, -50f, 0f);
     Y--;
     if (Geh > 0 && close== false)
         Moving();
     else
         CheckAngriff();
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by kilicbatuhan1205 · Jan 09, 2020 at 03:03 PM

I suspect that the while loop inside your Update method causes an infinite loop, which then crashes Unity. Check your conditions, e.g. print out the variables used in the condition statement.

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 Mr_Teels · Jan 10, 2020 at 04:50 PM 0
Share

yep. Same thought here! when using while you need to bee realy carefull to not make a infinite loop.

@ trollzor4674 ... international standart language for coders is english ;) even if you work alone on your project, try to write ALL in english. not everyone in forums can reed your german-english named variables.

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

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

Why does it crash when i put 1st person controller in Heirarchy ? 0 Answers

Is it bad to use static on [practically] everything? 2 Answers

Debugging and logging crashing? 1 Answer

Unity 5.3.2 Crashes on startup 0 Answers

Unity using way too much (+100%) cpu when object is in scene...even when game is not running (mac) 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