Hello, quangtien. For that, you would need to use a sine function. (Mathf.Sin)
I'll give you an example of what the code should look like. (in javascript)
Code:
var current_y : float; //The y of the object (before sin)
var change_y : float; //How fast you want it to change
var mult : float; //How far to go (like up or down)
var obj : Transform; //Object to move
function Update () {
current_y += change_y;
if (Input.GetKey (KeyCode.Space)) {
mult = 5;
} else
mult = 1;
}
if (current_y > 360) current_y -= 360;
obj.position.y = Mathf.Sin (current_y) * mult
}
That should be good. You should know some about trigonometry if you want to make scripts like this. This might be hard to understand without trigonometry.