switching back and forth between Cameras

hello All
I have 2 parallel roads (call them Good & Bad), and a character controller traversing one

At certain points, you mouseUp something & go to the other road and explore a bit …Fine.

But when you go back, either with user input, or via a timer,
I need you to go back to the exact position you were originally on when you left the first road
(are all variables global : i.e. move between scripts?)

So, the following partially work to translate camera but how to get it back is a mystery …

1) I would make a private variable called myPos to store the original position of the camera on the first mouseUp script:

var myCamera: Camera;

// set variable to hold my Current position:

private var myPos: int = (0, 0, 0);

function OnMouseUp () {

// I need to record the position of the Camera??

myCamera.position = myPos;

// move camera and set as active (works)

myCamera.transform.Translate(0,12,0);

myCamera.camera.enabled = true;

}

2) on the next MouseUp return camera to Position myPos:

var myCamera: Camera;

private var myPos: int;

function OnMouseUp () {

// I need to put the camera back to original position

myCamera.position = myPos

myCamera.camera.enabled = true;

}

Thanks So much !

Maybe you can just switch between cameras that way you don’t need to keep state. As long as one camera is enabled at a time you should be good. Hi I have a snippet where I switch from my main menu to the scene camera. Hope this points you in the right direction.

        private void Switch(bool showSceneCamera)
        {
                if (sceneCamera == null)
                        return;

                menuCamera.transform.gameObject.SetActive (!showSceneCamera);
                sceneCamera.transform.gameObject.SetActive(showSceneCamera);
                menuCamera.enabled = !showSceneCamera;
                sceneCamera.enabled = showSceneCamera;

                var listener = menuCamera.transform.GetComponent<AudioListener>();
                if (listener != null)
                {
                        listener.enabled = !showSceneCamera;
                }
                listener = sceneCamera.transform.GetComponent<AudioListener>();
                {
                        listener.enabled = showSceneCamera;
                }
                
        }

@morbidcamel
Thanks : I gave up and am using a version of the switch Cam you suggested. Though I am in Js : See bellow:

 public var L1_Camera : Camera;
    public var L2_Camera : Camera;
    
    function OnMouseUp() {
    
    	if (L1_Camera.camera.enabled == true) {
    		L2_Camera.camera.enabled = true;
    		L1_Camera.camera.enabled = false;
    	}
    	
    	else if (L2_Camera.camera.enabled == true) {
    		L1_Camera.camera.enabled= true;
    		L2_Camera.camera.enabled = false;
    	}
    
    }