# Elevator script problem (434731)

**URL:** https://discussions.unity.com/t/elevator-script-problem-434731/434731
**Category:** Scripting
**Tags:** Scripting
**Created:** [January 26, 2011, 5:26pm UTC](https://discussions.unity.com/t/elevator-script-problem-434731/434731 "2011-01-26T17:26:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_73236977](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon\_73236977](https://discussions.unity.com/u/anon_73236977)
#### Post date: [January 26, 2011, 5:26pm UTC](https://discussions.unity.com/t/elevator-script-problem-434731/434731/1 "2011-01-26T17:26:45Z")

</div>

I did this script for an elevator and I have a problem with it. This script should be added to the trigger the player should touch for the elevator to move. I want to make it stops when the position is equal to the floor2 position but it just seems to go on. What should I do

```auto
using UnityEngine;
using System.Collections;

public class BasicElevator : MonoBehaviour {
	public bool _isTriggered;
	public Transform elevatorBody;
	public Transform floor1;
	public Transform floor2;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(_isTriggered){
			elevatorBody.transform.Translate(Vector3.up * Time.deltaTime * 10);
		}
		if(elevatorBody.transform.position == floor2.transform.position){
			_isTriggered = false;
			Debug.Log("Floor2");
		}
	}
	
	void OnTriggerEnter(Collider other){
		if(other.CompareTag("Player")){
			_isTriggered = true;
		}
	}
}

```

---

<div class="post-metadata">

### Author: ![fallingbrickwork](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/fallingbrickwork/32/400505_2.png) [@fallingbrickwork](https://discussions.unity.com/u/fallingbrickwork)
#### Post date: [January 26, 2011, 7:57pm UTC](https://discussions.unity.com/t/elevator-script-problem-434731/434731/2 "2011-01-26T19:57:15Z")

</div>

not sure how you are testing it… ie, if you are remaining on the trigger etc…but…

one quick thing that jumps out is maybe the elevator is never actually getting to the EXACT height of the floor (this could be to the floating point etc)…try changing:

if(elevatorBody.transform.position == floor2.transform.position){

to

if(elevatorBody.transform.position \>= floor2.transform.position){

Regards,  
Matt.

---

<div class="post-metadata">

### Author: ![anon\_73236977](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon\_73236977](https://discussions.unity.com/u/anon_73236977)
#### Post date: [January 26, 2011, 8:09pm UTC](https://discussions.unity.com/t/elevator-script-problem-434731/434731/3 "2011-01-26T20:09:07Z")

</div>

Hey thanks it worked great! Ive just changed it to

if(elevatorBody.transform.position.y \>= floor2.transform.position.y){

and it worked perfect!

Thanks again!
