Forum rules - please read before posting.

Detecting which camera you're currently using

Hi all! Tried asking this on the Discord several days ago, but it seems to be dead? This forum is more active so I am posting here instead. Anyway, I am still sloowwwly working my way through learning AC and I have a question.

So I have two cameras in a scene. When my player moves across a trigger, the camera transitions to a different angle, and vice-versa. All well and good. What I'm wondering is if there's a way to check WHICH camera is being used at a given time? What I want is to check if the current camera is Camera A, then switch to Camera B if so (and vice versa).

Currently I make the check using a boolean that changes with the camera, but there are many places in the game that the camera can change and it's very messy to change the variable every time. It would be much easier and cleaner to just check which camera is being used. Is that possible?

Comments

  • There isn't an "official" Action to do this, but you can incorporate a custom Action that does.

    • you can check for this, and anything you need to - with the use of a custom Action.

    The currently active Camera is listed in the MainCamera's Inspector at runtime. Through script, this can be read with:

    AC.KickStarter.mainCamera.attachedCamera;

    (See the front page of the Scripting guide for a guide on how to access AC variables and components)

    Here's a custom Action you can use to check if a given camera is active or not:
    http://pasteall.org/1512358/csharp

  • Oh good! Scripting. :) I'll play around with that. THanks!

  • After spending some time figuring out how to add a custom action, this works like a charm! Thank you!

  • Hello! Sorry to hijack an old thread, but this is exactly a problem I am currently having. However, the code link no longer works, so I was wondering if you could provide access to the custom script again. Thanks to any who read this and can help out!

  • I believe this was it:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCameraCheck : ActionCheck
        {
    
            public _Camera cameraToCheck;
    
    
            public ActionCameraCheck ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Camera;
                title = "Check active";
                description = "Checks if a given Camera is currently active.";
            }
    
    
            public override bool CheckCondition ()
            {
                return (KickStarter.mainCamera.attachedCamera == cameraToCheck);
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                cameraToCheck = (_Camera) EditorGUILayout.ObjectField ("Check camera active:", cameraToCheck, typeof (_Camera), true);
            }
    
            #endif
    
        }
    
    }
    
  • Thanks Chris, it works like a charm.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.