Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Car3lessCrasher · Dec 08, 2020 at 07:18 PM · scripting problemfreeze

Unity freezes when script is run in play mode

I am trying to make a landing script for a plane and whenever the script runs it freezes Unity and I have to close it with Task Manager. Whenever I reopen unity the script is disabled due to it not saving when I activated it , and when I hit play without it being activated, it works fine, so it only freezes when the script is activated. Here is the script: Oh, and I use Unity 2018.1, If that is a factor in why it freezes.

 public class TieControl : MonoBehaviour {
     AudioSource audioSource;
     // Use this for initialization
     void Start () {
         // the is landed by default
         land = true;
     }
 
     // Update is called once per frame
     // when the landing variable is 1, that means it is taking off, when 2, that means it is landing, when 0, that means it has landed or is in the air.
     // when land is false, that means it is in the air, when true, that means it is on the ground landed.
      public bool land = true;
     public int landing = 0;
     void Update() {
         //default movement without input
         if (land == false)
             transform.Translate(0f, 0f, -0.2f);
 
         if (Input.GetKey(KeyCode.Space) & (land == false))
             landing = 2;
         if (Input.GetKey(KeyCode.Space) & (land == true))
             landing = 1;
         //everything under here is only if land is false
 
         if (Input.GetKey(KeyCode.W) & (land == false))
             transform.Translate(0f, 0f, -0.5F);
         if (Input.GetKey(KeyCode.S) & (land == false))
             transform.Translate(0f, 0f, 0.5f);
         if (Input.GetKey(KeyCode.A) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(0f, -0.5f, 0f);
         else if (Input.GetKey(KeyCode.A) & (land == false))
             transform.Rotate(0f, -1, 0f);
         if (Input.GetKey(KeyCode.D) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(0f, 0.5f, 0f);
         else if (Input.GetKey(KeyCode.D) & (land == false))
             transform.Rotate(0f, 0.5F, 0f);
         if (Input.GetKey(KeyCode.UpArrow) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(0.5f, 0f, 0f);
         else if (Input.GetKey(KeyCode.UpArrow) & (land == false))
             transform.Rotate(1f, 0f, 0f);
         if (Input.GetKey(KeyCode.DownArrow) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(-0.5f, 0f, 0f);
         else if (Input.GetKey(KeyCode.DownArrow) & (land == false))
             transform.Rotate(-1f, 0f, 0f);
         if (Input.GetKey(KeyCode.LeftArrow) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(0f, 0f, -0.5f);
         else if (Input.GetKey(KeyCode.LeftArrow) & (land == false))
             transform.Rotate(0f, 0f, -1f);
         if (Input.GetKey(KeyCode.RightArrow) & (Input.GetKey(KeyCode.S) & (land == false)))
             transform.Rotate(0f, 0f, 0.5f);
         else if (Input.GetKey(KeyCode.RightArrow) & (land == false))
             transform.Rotate(0f, 0f, 1f);
         //everything under here is if Landing is true to allow turning while landing
         if (Input.GetKey(KeyCode.A) & (landing == 2))
             transform.Rotate(0f, -0.2f, 0f);
         if (Input.GetKey(KeyCode.D) & (landing == 2))
             transform.Rotate(0f, 0.2f, 0f);
         //everything under here is the landing movement and the takeoff movement\
         //landing
         while (landing == 2)
         {
             transform.Translate(0f, -.2f, 0f);
 
             if ((landing == 2) & (transform.position.y == 40))
                 landing = 0;
         }
         //takeoff
         while (landing == 1)
         {
             transform.Translate(0f, .2f, 0f);
             land = false;
             landing = 0;
         }
     }
     //everything under here has to do with the collider
     // this will change landing to 0 when it collides with the terrain
     void OnTriggerEnter(Collider other)
         {
         print("The ship has landed");
         land = true;
         landing = 0;
             { };
         }
 
 
     
 }
 
 
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

2 Replies

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

Answer by highpockets · Dec 08, 2020 at 07:13 PM

Your while loops are blocking/stopping the thread and landing will never change to 1 or 2 while it’s in there because the Update method will not be run again. You have to rethink your logic. Either take those while loops out of Update and put them in coroutines with yield statements or work out a way to include the while loop logic within your Update function without blocking the main thread

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
avatar image
0

Answer by Car3lessCrasher · Dec 14, 2020 at 12:40 PM

OK, thanks!

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

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

Unity freezes when slider code is enabled. 0 Answers

Unity Crashes When Clicking Play: Script Error? 1 Answer

Unity freezes. I dont know why... 3 Answers

Unity freeze on certain condition. 0 Answers

Animation frezzing on first few frames android 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