Camera Auto switching when in collision

Hello, I’m also a beginner, Here is a basic c# codes of auto camera switching when a player hits the box collider of the camera just like resident evil 1,2 and 3.

First, you have cameras in every corner of your game, disable all cameras from your inspector to prevent the bug. Drag your 1 camera to camera1 and camera2., repeatt the process until you finish it. Add box collider or any collider(expand it) to your cameras that can hit it by your player and check the box of IS TRIGGER. The use of Camera1 is to enable the camera view when a player hits the collider, the use of Camera2 is to turn off the camera after you exit in the range of collider. I just modified the multiple surveilance camera js tutorial from Design3D.

if anyone found bugs please modify it and help us becuase im also a beginner :slight_smile:
thank you.

using UnityEngine;
using System.Collections;

public class cameraswitch1 : MonoBehaviour {
	public Camera camera1;
	public Camera camera2;
	
	void OnTriggerEnter(){
		camera1.enabled = true;			
	}
	void OnTriggerExit(){
		camera2.enabled = false;	
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

This is a very interesting concept. Perhaps though you could look at it as an overall concept using only 1 camera. So lets say that the initial view is like a mouse orbit camera. But when you walk up to a door, the camera swaps to a long view. Or in the case of what you are suggesting, it looks like it is coming from a security camera. The camera doesn’t swap cameras, it simply changes the position and rotation to match the new camera.

i think that is too hard for me. i have a question, is c# from unity different from visual c# from microsoft? because when i’m using visual c# 2010 it’s easy for me to use it but when im using unity c# i really can’t understand the programming in unity.

It’s mostly the same; I’d guess that any difficulties you’re having are actually with the Unity API and engine architecture rather than with C# itself.

awesom work! I really appreciate it!
The script is very powerfull and easily as flexible to adjust.

so far I used it for:

  • room-camera (oviously)
  • switch to fps camera (deactivate all room cameras)
  • single realtime light at the time