#pragma strict

public var speedDown : float = 2;
public var speedUp : float = 2;
private var MyTransform : Transform;
private var HasMoved : boolean = false; 
private var OriginalPosition : Vector3;
private var IsFPCOver : boolean = false; 

function Start () {
	//MyFPC = GameObject.Find("First Person Controller");
	MyTransform = this.transform.parent;
	OriginalPosition = MyTransform.position;
}

function Update () {
	if(HasMoved && !IsFPCOver){
		MyTransform.Translate(Vector3.up * speedUp * Time.deltaTime, Space.World);
		if(MyTransform.position.y >= OriginalPosition.y){
			MyTransform.position = OriginalPosition;
			HasMoved = false;
		}
	}
}

function OnTriggerStay (other : Collider) {
	//Debug.Log("OnPlane");
	if(other.transform.tag == "Player"){
		if(!HasMoved){
			HasMoved = true;
			IsFPCOver = true;
		}
		MyTransform.Translate(-Vector3.up * speedDown * Time.deltaTime, Space.World);
		if(MyTransform.position.y <= 1)
			MyTransform.position.y = 1;
	}
}


function OnTriggerExit (other : Collider) {
	if(other.transform.tag == "Player")
		IsFPCOver = false;
}