making an object move up and down

hello, I have an object i want to pop up and down through the terrain/ hole in the terrain, like the spikes that go up and down in the sonic the hedgehog games.

ideally i would like the spikes to pop up wait a few seconds then pop back down for a few seconds.

any ideas how to script this (i tend to code in javascript)?

thanks matt

You can also use the Animation Editor to create the movement, then a smaller JS to trigger it

To make an object move up and down you mess with the transform of the gameobject. Since you want to move the object mess with the position.

In order to get something to happen after a few seconds use the yield and waitforseconds command.

#pragma strict
var upDown:float;
var speed:int = 2;
var hightDiv:int = 150
var t:float;
function Start () {


function Update () {

transform.Translate(Vector3.up * upDown);
t += speed *(Time.deltaTime);
upDown = (Mathf.Sin(t))/hightDiv;