Created
March 6, 2022 10:09
-
-
Save BarakChamo/f219050dfa685c5e349f649fc2dba103 to your computer and use it in GitHub Desktop.
Unity tag content activator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System.Linq; | |
public class CameraContentActivator : MonoBehaviour { | |
//to use this code, tag all your wall cameras first. | |
//NorthCam, SouthCam, EastCam, WestCam, FloorCam | |
public GameObject[] northContent; | |
public GameObject[] southContent; | |
public GameObject[] eastContent; | |
public GameObject[] westContent; | |
public GameObject[] floorContent; | |
Camera streamCamera; | |
void Start() { | |
StartCoroutine(LookForStreamCam()); | |
} | |
IEnumerator LookForStreamCam() { | |
while (streamCamera == null) { | |
// no stream camera found, skip loop | |
yield return new WaitForSeconds(.5f); | |
//look for all active cameras | |
var cams = GameObject.FindObjectsOfType<Camera>(); | |
// find the stream camera | |
try { | |
streamCamera = cams.First(cam => cam.gameObject.name.ToLower().Contains("stream")); | |
} catch (System.Exception) { | |
Debug.Log("No stream camera found..."); | |
continue; | |
} | |
GameObject[] targets = {}; | |
// match activation content | |
switch(streamCamera.tag) { | |
case "NorthCam": | |
Debug.Log("Found NorthCam stream camera!"); | |
targets = northContent; | |
break; | |
case "SouthCam": | |
Debug.Log("Found SouthCam stream camera!"); | |
targets = southContent; | |
break; | |
case "WestCam": | |
Debug.Log("Found WestCam stream camera!"); | |
targets = westContent; | |
break; | |
case "EastCam": | |
Debug.Log("Found EastCam stream camera!"); | |
targets = eastContent; | |
break; | |
case "FloorCam": | |
Debug.Log("Found FloorCam stream camera!"); | |
targets = floorContent; | |
break; | |
} | |
foreach (var target in targets) { | |
target.SetActive(true); | |
} | |
yield break; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment