I have a couple issues with my current door script. So far i can open and close doors my dragging the mouse up or down. However my problems are that:

There are multiple doors facing different directions, and i dont know how to keep track of each door’s individual rotation

If i open a door, go behind it, then try to close it, i have to move mouse in opposite direction for it to work.

if i open a door, then open another door, then go back to the previous door, the minimum rotation starts off where it ended, which is fully opened.
var mouseX : float = 0;
var rotSpeed : float = 10;
var minX : float = 0;
var maxX : float = 0;
private var cam : GameObject;
var mouseYAxis : float;
var flipMouseAxis : boolean = false;
var swapYforX : boolean = false;
function Start() {
cam = GameObject.FindWithTag(“camera”);
//if door is facing the x axis, make sure it rotates negatively
if(transform.forward == Vector3.right) {
minX = transform.eulerAngles.y  80;
maxX = transform.eulerAngles.y;
mouseX = maxX;
flipMouseAxis = true;
} else {
minX = transform.eulerAngles.y;
maxX = transform.eulerAngles.y + 80;
}
}
function DoorOpen() {
forward = cam.transform.TransformDirection(cam.transform.forward);
doorPos = transform.InverseTransformDirection(transform.position);
camPos = transform.InverseTransformDirection(cam.transform.position);
doorDistance = doorPos  camPos;
forward.Normalize();
doorDistance.Normalize();
if(Vector3.Dot(forward, doorDistance) < 0) {
Debug.Log("door is in front of us: "+ Vector3.Dot(forward, doorDistance));
mouseX += mouseYAxis * rotSpeed;
mouseX = Mathf.Clamp(mouseX, minX, maxX);
} else {
Debug.Log(“door is behind us”+ Vector3.Dot(forward, doorDistance));
mouseX = mouseYAxis * rotSpeed;
mouseX = Mathf.Clamp(mouseX, minX, maxX);
}
//make axis move negative since door is facing x axis
if(flipMouseAxis == true) {
mouseYAxis = Input.GetAxis(“Mouse Y”);
} else { mouseYAxis = Input.GetAxis(“Mouse Y”); }
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(0, mouseX, 0), 2);
}
I know that there are multiple questions here, and that they are confusing to understand, but my problems are hard to explain so bare with me. Any help with any of these problems would be appreciated. I was thinking about making an array keeping track of the doors and their rotations, but im not sure how to implement that. A dictionary doesnt seem to work.