I have two elevators next to each other running the same script. They are very close to each other and this can’t be changed in the level.
The problem is I can open one of the elevators fine but if I’m too close to the adjacent one when doing this or if I’m inside one elevator and press E I open the other one.
This is the layout of my elevators:

The elevator on the right opens when I press E when inside or too far to the right of the elevator on the left but not the other way around.
This is the script I’m using:
using UnityEngine;
using System;
using System.Collections;
public class Elevator : MonoBehaviour {
private float maxDistance = 5.5f;
public Transform elevator;
public bool open = false;
public bool verbose = false;
public void Update() {
GameObject player = GameObject.FindGameObjectWithTag("Player");
float distance = Vector3.Distance(elevator.transform.position, player.transform.position);
if(verbose) Debug.Log("Distance : " + distance);
if(Input.GetKeyDown("e") && distance < maxDistance && !open) {
elevator.animation["Default Take"].speed = 1;
elevator.animation.Play("Default Take");
open = true;
if(verbose) Debug.Log("Elevator Opening");
} else if(open && distance > maxDistance && !elevator.animation.IsPlaying("Default Take")) {
elevator.animation["Default Take"].speed = -1;
elevator.animation["Default Take"].time = elevator.animation["Default Take"].length;
elevator.animation.Play("Default Take");
open = false;
if(verbose) Debug.Log("Elevator Closing");
}
}
public void Start() {
}
}
I can verify that the elevator Transforms are correct. I have transitioned over to using BoxColliders now, thanks for your help.
– MrDare360No worries, let me know how it goes.
– ThePunisher