How to moving objects up and down slowly?

Hi, as you guys don’t know, I am new to Unity3D but I am learning quikly, so complex code is welcome.

However, coming to the point, I have blocks (huge blocks like buildings) in my game as a background, what I need is to move the objects, if it can, move the blocks randomly up and down.
So it’s creating a nice effect int the background, but I don’t want to animate it, because I am already instantiating and looping the blocks randomly in a size of x and y in the background.

Here you go! Just adjust the vaues to yourliking :wink:

Good luck!

var maxUpAndDown 			: float	= 1; 			// amount of meters going up and down
var speed 					: float = 200;			// up and down speed
protected var angle			: float = 0;			// angle to determin the height by using the sinus
protected var toDegrees 	: float	= Mathf.PI/180;	// radians to degrees

function Update()
{
	angle += speed * Time.deltaTime;
	if (angle > 360) angle -= 360;
	transform.position.y = maxUpAndDown * Mathf.Sin(angle * toDegrees);
}

Here u go!

Only when you adjust the MaxUpAndDown you have to reload the game

var maxUpAndDown			: float = 1;			// amount of meters going up and down
var speed					: float = 50;			// up and down speed

protected var angle			: float = -90; 			// angle to determin the height by using the sinus
protected var toDegrees		: float = Mathf.PI/180;	// radians to degrees
protected var startHeight 	: float;				// height of the object when the script starts


function Start()
{
	startHeight = transform.localPosition.y;
}

function FixedUpdate()
{
	angle += speed * Time.deltaTime;
	if (angle > 270) angle -= 360;
	Debug.Log(maxUpAndDown * Mathf.Sin(angle * toDegrees));
	transform.localPosition.y = startHeight + maxUpAndDown * (1 + Mathf.Sin(angle * toDegrees)) / 2;
}