CameraController and ReactiveCamera + Prefab for CameraWithTrigger and
Frank added
This commit is contained in:
40
Assets/AssetsFORELLE/Script/CameraController.cs
Normal file
40
Assets/AssetsFORELLE/Script/CameraController.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
11
Assets/AssetsFORELLE/Script/CameraController.cs.meta
generated
Normal file
11
Assets/AssetsFORELLE/Script/CameraController.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c367d6ffd5aab154a8e755b921c7176c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/AssetsFORELLE/Script/ReactiveCamera.cs
Normal file
33
Assets/AssetsFORELLE/Script/ReactiveCamera.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/AssetsFORELLE/Script/ReactiveCamera.cs.meta
generated
Normal file
11
Assets/AssetsFORELLE/Script/ReactiveCamera.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d469014f8afb2d4ea0308a0a86bef05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user