CameraController and ReactiveCamera + Prefab for CameraWithTrigger and

Frank added
This commit is contained in:
GungHolo
2023-06-06 22:10:54 +02:00
parent 8d381baffd
commit 645c21bb95
10 changed files with 3798 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
Static Class which takes role of Controller for all the Cameras/Triggers
IMPORTANT!!!
The Priority of the FIRST Camera that should be shown has to be set manually to 100
The Priorities of the OTHER cameras can be anything else then 100
IMPORTANT!!!
*/
public static class CameraController
{
public static Camera currentCam;
static List<Camera> cameras = new List<Camera>();
public static void Register(Camera cam)
{
cameras.Add(cam);
}
public static void ActivateCamera(Camera cam)
{
cam.depth = 100;
currentCam = cam;
foreach (Camera c in cameras)
{
if(c != currentCam) c.depth = 0;
}
}
public static Camera CurrentCamera()
{
return currentCam;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c367d6ffd5aab154a8e755b921c7176c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
Sends the necessary Requests to the CameraController saying "Hi i want to be rendered"
The CameraController then obliges like the nice Guy he is :)
*/
public class ReactiveCamera : MonoBehaviour
{
[SerializeField] private Camera cam;
[SerializeField] private EdgeCollider2D col;
Rigidbody2D rb;
void Start()
{
col = GetComponent<EdgeCollider2D>();
rb = GetComponent<Rigidbody2D>();
cam = GetComponentInChildren<Camera>();
rb.isKinematic = true;
CameraController.Register(cam);
}
// Update is called once per frame
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.CompareTag("Player"))
{
if(CameraController.CurrentCamera() != cam) CameraController.ActivateCamera(cam);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d469014f8afb2d4ea0308a0a86bef05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: