Quantcast
Viewing all articles
Browse latest Browse all 80

Answer by ransomink

This is an easy script that will switch the camera upon entering the trigger and revert back to the previous camera when exiting the trigger. Attach this to the trigger GameObject. // INSPECTOR VARIABLES // public var switchToCamera : Camera;// the camera to switch to (when trigger is entered) // PRIVATE VARIABLES // private var currentCamera : Camera;// the current camera being rendered private var previousCamera : Camera;// the previous camera that 'was' being rendered (the current camera before entering the trigger). // when the trigger is entered - switch cameras function OnTriggerEnter ( col : Collider ) { currentCamera = Camera.current; previousCamera = currentCamera; currentCamera.enabled = false; currentCamera = switchToCamera; currentCamera.enabled = true; } // when the trigger is exited - revert back to previous camera function OnTriggerExit ( col : Collider ) { currentCamera.enabled = false; currentCamera = previousCamera; currentCamera.enabled = true; previousCamera = null; } You can change the currentCamera and previousCamera from private to public if you wish to see the camera status update inside the inspector.

Viewing all articles
Browse latest Browse all 80

Trending Articles