Stopping the elevator

This is my code for the movement of an elevator. I need to create a GUI button to stop the movement at any time. How can I do that?

var elevator : GameObject; 
var trigger : GameObject; 
var elevatorDoors : GameObject; 
var elevatorDoorsExt : GameObject; 

private var elevatorHeight : float; 
private var triggerHeight : float; 

private var elevatorActive : boolean; 

var elevSpeed = 0.1; 

function Start() 
{ 
elevatorHeight = elevator.transform.position.y; 
triggerHeight = trigger.transform.position.y; 

elevatorActive = false; 
} 

function Update() 
{ 
if(elevatorActive == true) 
{ 
networkView.RPC("CallElevator", RPCMode.All); 
} 
elevatorActive = false; 
} 

@RPC 
function CallElevator() 
{ 
while(elevatorHeight > triggerHeight) 
{ 
elevatorHeight = Mathf.Ceil(elevator.transform.position.y); 
triggerHeight = Mathf.Ceil(trigger.transform.position.y); 
elevator.transform.Translate(Vector3(0, 0 , -elevSpeed*Time.deltaTime));    
yield; 
} 

while(elevatorHeight < triggerHeight) 
{ 
elevatorHeight = Mathf.Floor(elevator.transform.position.y); 
triggerHeight = Mathf.Ceil(trigger.transform.position.y); 
elevator.transform.Translate(Vector3(0, 0 , elevSpeed*Time.deltaTime)); 
yield; 
} 

if(elevatorHeight == triggerHeight) 
{   
elevatorActive = false; 
yield new WaitForSeconds(5.0); 
elevatorDoors.animation.Play("open"); 
elevatorDoorsExt.animation.Play("open"); 

yield new WaitForSeconds(5.0); 
elevatorDoors.animation.Play("close"); 
elevatorDoorsExt.animation.Play("close"); 
yield; 
} 
} 

@RPC 
function StopElevator() 
{ 
print("StopElevator"); 
elevatorActive = false; 
} 

function Call() 
{ 
elevatorActive = true; 

} 

function Stops() 
{ 
networkView.RPC("StopElevator", RPCMode.All); 
}

You'd make the button execute a script that makes the elevator stop, so by reducing all forces acting on it.

The elevator continues moving because the RPC is still running. It was started when elevator active was true. You should try wrapping all the movement inside the "CallElevator" function with an if statement checking if elevator active is still true:

@RPC 
function CallElevator() 
{ 
  while(elevatorHeight > triggerHeight) 
  { 
    if(elevatorActive == true) 
    { 
      elevatorHeight = Mathf.Ceil(elevator.transform.position.y); 
      triggerHeight = Mathf.Ceil(trigger.transform.position.y); 
      elevator.transform.Translate(Vector3(0, 0 , -elevSpeed*Time.deltaTime));  
    }  
    yield;
  } 

  while(elevatorHeight < triggerHeight) 
  { 
    if(elevatorActive == true) 
    { 
      elevatorHeight = Mathf.Floor(elevator.transform.position.y); 
      triggerHeight = Mathf.Ceil(trigger.transform.position.y); 
      elevator.transform.Translate(Vector3(0, 0 , elevSpeed*Time.deltaTime)); 
    }
    yield; 
  }

  if(elevatorHeight == triggerHeight) 
  {   
    elevatorActive = false; 
    yield new WaitForSeconds(5.0); 
    elevatorDoors.animation.Play("open"); 
    elevatorDoorsExt.animation.Play("open"); 

    yield new WaitForSeconds(5.0); 
    elevatorDoors.animation.Play("close"); 
    elevatorDoorsExt.animation.Play("close"); 
    yield; 
  } 
}