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
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;
}
}
}