Forum rules - please read before posting.

camera onenable

Is there a way to add a actionlist that runs when sertain camera is enabled and another when it is disabled? Or should I just use a standard script with these onenable/ disable functions?

Comments

  • For this kind of functionality, you want to make use of custom events, which are a way of triggering custom code when AC performs common tasks - including switching camera.

    Such code can be used to trigger an ActionList when a given camera is switched to/from. For example:

    using UnityEngine;
    using AC;
    
    public class CameraEventExample : MonoBehaviour
    {
    
        public _Camera cameraToReactTo;
        public ActionList actionListOnEnable;
        public ActionList actionListOnDisable;
    
        private void OnEnable () { EventManager.OnSwitchCamera += SwitchCamera; }
        private void OnDisable () { EventManager.OnSwitchCamera -= SwitchCamera; }
    
        private void SwitchCamera (_Camera oldCamera, _Camera newCamera, float tt)
        {
            if (newCamera == cameraToReactTo)
            {
                actionListOnEnable.Interact ();
            }
            else if (oldCamera == cameraToReactTo)
            {
                actionListOnDisable.Interact ();
            }
        }
    
    }
    

    See the Manual's "Custom events" chapter for more on this topic.

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.