how to spawn 2d object in unity code example

Example 1: how to make % posibility to spawn an object in unity

if(Random.value > 0.5) //%50 percent chance {//code here }  if(Random.value > 0.2) //%80 percent chance (1 - 0.2 is 0.8) { //code here }  if(Random.value > 0.7) //%30 percent chance (1 - 0.7 is 0.3) { //code here }

Example 2: how to move a 2d character in unity

if (moveInput != 0)
{
	velocity.x = Mathf.MoveTowards(velocity.x, speed * moveInput, walkAcceleration * Time.deltaTime);
}
else
{
	velocity.x = Mathf.MoveTowards(velocity.x, 0, groundDeceleration * Time.deltaTime);
}

Tags:

Misc Example