When I put Time.deltaTime or Time.fixedDelltaTime in for or a while, Unity freeze

Greetings,

When I put Time.deltaTime in a While or a For, it freezes Unity. Is it normal?

function spawnNew(){

	//Put all the boss spawns in an array

	var bossSpawns = new Array();

	bossSpawns = GameObject.FindGameObjectsWithTag ("bossSpawn");

	

	//Returns a random boss spawn.

	var selectedBossSpawn = bossSpawns[Random.Range(0,bossSpawns.length-0.01)];

	print(selectedBossSpawn);

	//Place the Boss at the selectedBossSpawn.

	transform.position = selectedBossSpawn.transform.position;

	var x = 0;

	while(x<=5){

		rigidbody.velocity = spawnVelo * selectedBossSpawn.transform.forward;

		x+=Time.deltaTime;

	}

}

This isn’t exactly because of the Time.deltaTime.

It’s more because of your use of a while loop to model behaviour that is supposed to occur over several frames. A while loop needs to resolve before the next frame will be reached- if you want to wait for 5 seconds, you need to use a Coroutine with the ‘WaitForSeconds’ command.

In this case, you should use

rigidbody.velocity = (whatev);
yield WaitForSeconds(5);

Is this related to your question about freezing an object’s velocity, by the way? If you want to have an object keep moving at a constant velocity, you should just make the rigidbody kinematic and move it manually. If you want to have realistic collisions, you can try setting its drag to 0 and disabling gravity (space-like). Otherwise, you will need to check for collisions manually.