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 ![]()
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 () {
}
}