Skip to content

Instantly share code, notes, and snippets.

@fongreecss
Created May 28, 2020 14:40
Show Gist options
  • Save fongreecss/4e709eaced74c91888235321c89ce980 to your computer and use it in GitHub Desktop.
Save fongreecss/4e709eaced74c91888235321c89ce980 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**
* Vsakemu switcherju oz boxu, ki spreminja pač kamero se doda tag, ki mora biti ime kamere na katero želi preklopit
* Vsak switcher mora imet to skripto not. Skripts-> CameraSwitcher
*
* */
public class CameraSwitcher : MonoBehaviour
{
// Start is called before the first frame update
private Camera[] cameras = null;
private Camera activeCamera = null;
void Start()
{
this.cameras = Camera.allCameras;
}
// Update is called once per frame
void DisableEveryCamera()
{
foreach(Camera cam in Camera.allCameras)
{
Debug.Log(cam.name + " is disabled");
cam.enabled = false;
}
}
void Update()
{
}
private void OnTriggerEnter(Collider coll)
{
try
{
DisableEveryCamera();
activeCamera = GameObject.Find(this.gameObject.tag).GetComponent<Camera>();
activeCamera.enabled = true;
} catch(System.Exception ex)
{
Debug.Log(ex.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment