On applying this code Unity is hanging. What is wrong with the code?

public var speed : float;
//var check : float;
function Start () {

}

function Update()
{
	while(transform.position.x != 15f)
	{
		transform.position.x += speed * Time.deltaTime;
                yield WaitForSeconds(0);
	}
	transform.position.x -= speed * Time.deltaTime;
}

Once the code is formatted properly it becomes obvious

  1. You are trying to make Update a coroutine
  2. You are comparing floats directly

Because the code is not properly formatted. :wink:

The actual reason is that you are comparing float values using == operator which is very very very less likely scenario. Hence your loop is going into infinity.

Use Mathf.Approximately to compare like:

while(!Mathf.Approximately(transform.position.x, 15f))