my unity is freezing when adding prefab to script

unity keep freezing when ever i add my players prefab to the script. after i press the play button the game just sorta loads then fails and shuts down.... i dont know why or what the issue is any ideas would help.

// T1=tech 1 M=max C=current H=health E=energy 
private var T1MH : float = 100;
private var T1CH : float = 100;
private var T1ME = 100;
private var T1CE = 100;
var playerpref : Transform;
var Regen : float = 1;
private var dead = false;

function OnGUI(){
GUI.Label(Rect(500,775,150,150),"Health");
GUI.Label(Rect(115,10,150,180), T1CH+"/"+T1MH);
GUI.Label(Rect(10,40,150,150),"Energy");
GUI.Label(Rect(115,40,150,180), T1CE+"/"+T1ME);
}

function Awake () {

Instantiate (playerpref);

}

function Update(){

// dead equals true and desotry game object
if (dead){
Destroy(gameObject.FindWithTag("playerpref"));
WaitForSeconds(2);
Instantiate(playerpref);
}

//makes dead true
if (T1CH <= 0.0) {
dead = true;
}

// makes T1CH stop at 0
if (T1CH < 1) {
T1CH = 0.0;
}

//regen
 if(T1CH < T1MH){
    T1CH += Regen * Time.deltaTime;
    }
    //Admin Dmg
if  (Input.GetKeyDown(KeyCode.I)) {
    T1CH -= 50;
    Debug.Log("You have Taken Damage!");
    }
 }

1 Answer

1

you cant have waitforseconds in function update

also i dont think your instantiate would work properly because you didn't declare playerpref