Unity is freezing and I cannot figure out why

I am making a card game and when I hit play unity is freezing. Could you please help me find what in my code is causing this? Thanks!
using UnityEngine;
using System.Collections;

public class Deck : MonoBehaviour {
	public GameObject Card;
	public GameObject[] Cards;
	public float deckSize;
	private int decklength;
	public float offset;
	private string[] cardNames = {"aC","2C","3C","4C","5C","6C","7C","8C","9C","10C","jC","qC","kC","aD","2D","3D","4D","5D","6D","7D",
								"8D","9D","10D","jD","qD","kD","aH","2H","3H","4H","5H","6H","7H","8H","9H","10H","jH","qH","kH",
								"aS","2S","3S","4S","5S","6S","7S","8S","9S","10S","jS","qS","kS"};

	private float startTime;
	private float journeyLength;
	public float speed = 1.0f;
	// Use this for initialization
	void Start () {
		decklength = Mathf.RoundToInt(deckSize); 
		Cards = new GameObject[decklength]; 
		offset =  1 / deckSize;

		for (int i = 0 ; i < decklength; i++)
		{
			GameObject go = Instantiate(Card,transform.position + new Vector3(0, i*offset, 0),transform.rotation) as GameObject;
			Cards *= go;*

_ Cards*.transform.parent = transform;_
Cards_.name = cardNames;
}*_

* Shuffle();*
* }*

* // Update is called once per frame*
* void Update () {*

* }*
* void Shuffle ()*
* {*
* for (int i = 0 ; i < decklength; i++)*
* {*
_ GameObject tmp = Cards*;
int r = Random.Range(i,decklength);
Cards = Cards[r];
Cards[r] = tmp;
}*_

* for (int i = 0 ; i < decklength; i++)*
* {*
_ Vector3 pos1 = Cards*.transform.position;
Vector3 pos2 = transform.position + new Vector3(0, ioffset, 0);

* startTime = Time.time;
journeyLength = Vector3.Distance(pos1, pos2);*_

_ while(Cards*.transform.position != pos2)
{
float distCovered = (Time.time - startTime) * speed;
float fracJourney = distCovered/journeyLength;
Cards.transform.position = Vector3.Lerp(pos1, pos2, fracJourney);
}*_

* }*
* }*
}

On reading your post title, I looked for and found the keyword behind most "Unity is freezing" - which is "while". Look at your while code, it's probably in an infinite loop.

1 Answer

1

On reading your post title, I looked for and found the keyword behind most “Unity is freezing” - which is “while”. Look at your while code, it’s probably in an infinite loop.