Script freezes Unity

Well I have this problem I have made this script so that the object moves, theres no error in the console yet Unity3d Freezes when I enter play mode, what could I do wrong? :face_with_spiral_eyes:

var health : float = 100;
var atack : boolean = false;


var speed : float = 10;
var damage : float = 5;
// + if plyr1 - if plyer2
var PlyStatus : float = 1;


function Start () {
transform.LookAt(target);
atack = false;

}


function Update(){
while (atack == false)
	{
	
	rigidbody.AddForce(PlyStatus * speed * Time.deltaTime,0,0);
	}
if(health <= 0)
	{
	Destroy(gameObject);
	}
}




function OnTriggerEnter (col : Collider)
{
	if(col.gameObject.tag == "Player2")
	{
	atack = true;
	col.GetComponent(AI).health -= damage;
	}
}

The game never goes past the first update because it is stuck in that while loop.

You should change it to an “if” if you want it to run across multiple frames.

Yeah it is also kinda interesting why you chose if in all other places except that one.

most of the time, you should “AddForce” in the FixedUpdate. :wink:

Ok thanks I really wanted to try the while function for peformance but o well, well It stil seem not to work, so I changed the rigidbody to a rigidbody.translate and it worked!

Thank you all!