Trying to implement pressure pad in game help.

Hi all What I trying to do is implement a pressure pad within my terrain so that when the character steps on it, it depresses into the terrain. All I got for it is a cube set midway through the terrain with the following script attached:

function FixedUpdate() { var dwn = transform.TransformDirection(Vector3.down); transform.Translate(0, -0.1*Time.deltaTime, 0); }

As your well aware this only make the cube keep going through the terrain. Help much appreciated.

function MoveDown (thisTransform : Transform, distance : float, speed : float) {
    var startPos = thisTransform.position.y;
    var endPos = startPos - distance;
    var rate = 1.0 / Mathf.Abs(startPos - endPos) * speed;
    var t = 0.0;
    while (t < 1.0) {
        t += Time.deltaTime * rate;
        thisTransform.position.y = Mathf.Lerp(startPos, endPos, t);
        yield; 
    }
}

Then you can do

MoveDown (transform, .5, 2.0);

to make `transform` move down .5 units at 2 units per second.