Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Unity Editor stop responding (hangs) when add script to GameObject.

Discussion in 'Scripting' started by michaljabrzyk, Jul 11, 2020.

  1. michaljabrzyk

    michaljabrzyk

    Joined:
    Apr 15, 2013
    Posts:
    58
    Hi. Problem is when I try to add script to gameObject. Unity editor stop responding and I have to restart.
    Script is simple like a problem . But create another project wit other name and problem against.
    What to do?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [ExecuteInEditMode]
    6.  
    7. public class A1 : MonoBehaviour
    8. {
    9.  
    10.     [Range(1, 360)]
    11.     public int _A = 2;
    12.     public int _C;
    13.     public int T;
    14.  
    15.     public int[] Points;
    16.     public int[] X_;
    17.     public int[] Y_;
    18.     public int[] Z_;
    19.  
    20.     private int Index_;
    21.     private int e;
    22.  
    23.     // Start is called before the first frame update
    24.     void Start()
    25.     {
    26.        
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void Update()
    31.     {
    32.         Debug.Log("Work's");
    33.  
    34.         Index_ = 0;
    35.         T = _A * _A;
    36.         _C = T * 3;
    37.  
    38.         Points = new int[_C];
    39.         X_ = new int[T];
    40.         Y_ = new int[T];
    41.         Z_ = new int[T];
    42.  
    43.         Cal();
    44.     }
    45.  
    46.     public void Cal()
    47.     {
    48.         int a = _A;
    49.  
    50.         if (a == _A)
    51.         {
    52.             Debug.Log("Cal(); -- Initiation");
    53.             for (e = 1; e <= _A; e++)
    54.             {
    55.                 Debug.Log("Cal(); -- First Loop");
    56.                 Debug.Log("j = " + e);
    57.  
    58.                 if (_A > 1) { Index_++; }// = Index_ + 1; }
    59.  
    60.                 for (; Index_ <= e + 2;)
    61.                 {
    62.                     Debug.Log("Cal(); -- Secound Loop");
    63.                     Debug.Log("Index_ = " + Index_);
    64.                 }
    65.             }
    66.         }
    67.     }
    68. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,851
    Not sure about all this logic, but I know that you enter a loop at line 60 with the exit condition being based on
    Index_
    and
    e
    variables, and neither of those are changed inside the loop.
     
  3. michaljabrzyk

    michaljabrzyk

    Joined:
    Apr 15, 2013
    Posts:
    58
    Your right. Fixed. THX :)