How can this be an infinite loop / crashing the program?

Hi,

I have a game object that plays an animation, after the animation is done, I want to clone this object on its origin position and play another animation with the cloned one.

I know how weird unity handles easiest wished so for the moment I just wanted to do the following: Play the animation and clone the object on its old place. I absolutely do not understand, why my Unity crashes everytime I execute this code - I guess it’s because of an infinite loop but where the fuck is there an infinite loop ? o0

This is my code:

#pragma strict

var cardGeneral:GameObject;
var cardCounter:int=0;

function Awake(){
    animation.Play("giveCardPlayer");
	while(cardCounter<3){
		createCard();
	}
}

function createCard(){
	Instantiate(cardGeneral,transform.position,transform.rotation);
	cardCounter++;
}

I am guessing you are instanciating the gameobject that has this script.
So basically each time you instanciate the script (gameobject), you generate 3 new GO.
So you see the issue :slight_smile:
Each object is generating three objects (that are generating three objects each, and so on).

Edit:
Awake() is executed each time you spawn a new item.