logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityGameCameraSwitchTriggerComponent

    No-code camera switch: placed on a trigger volume, it makes its target camera the only active camera through IGameCameraSwitchHolds while an admitted visitor is inside, and — when the author asks for it — makes the camera that was active before active again once the camera is no longer held.

    Inheritance
    object
    UnityGameCameraSwitchTriggerComponent
    Namespace: Serenity.GameCamera.Infrastructure.Components
    Assembly: Serenity.UnityGameCamera.Infrastructure.dll
    Syntax
    public class UnityGameCameraSwitchTriggerComponent : UnityTriggerVolumeComponent
    Remarks

    The volume takes one hold on its target camera when its first visitor walks in and releases it when its last visitor leaves, or when the volume is disabled or destroyed with visitors inside — a torn-down room never leaves the camera switched. A visitor destroyed or switched off inside the volume (an enemy killed, an object returned to a pool) counts as having left within a few fixed updates, so it never holds the camera either. Two volumes switching to the same camera (two entrances to one arena) share it: the camera is handed back only when the last hold on it is released, and the volume releasing that last hold decides, through its Restore Previous On Exit, whether the camera active before comes back. The camera service's exclusive switch does the work: every other registered camera is disabled, never its GameObject; a target the scene starts with off is turned on, and one the service did not know before is handed back unregistered and on or off as the scene had it. If something else chose another camera in the meantime, that camera stays. The core boot installs the Game Camera module; a scene played without that boot has no module, and the trigger then warns once instead of throwing.

    Constructors

    UnityGameCameraSwitchTriggerComponent()

    Declaration
    public UnityGameCameraSwitchTriggerComponent()

    Properties

    HasSwitched

    True while this trigger holds its target camera switched on.

    Declaration
    public bool HasSwitched { get; }
    Property Value
    Type Description
    bool

    RestorePreviousOnExit

    Whether the camera active before comes back when this volume releases the last hold on its target.

    Declaration
    public bool RestorePreviousOnExit { get; set; }
    Property Value
    Type Description
    bool

    TargetCamera

    The camera that becomes the only active camera while an object is inside this volume.

    Declaration
    public Camera TargetCamera { get; set; }
    Property Value
    Type Description
    Camera

    Methods

    OnAdmittedObjectEntered(GameObject)

    Declaration
    protected override void OnAdmittedObjectEntered(GameObject enteringVisitor)
    Parameters
    Type Name Description
    GameObject enteringVisitor

    OnAdmittedObjectExited(GameObject)

    Declaration
    protected override void OnAdmittedObjectExited(GameObject exitingVisitor)
    Parameters
    Type Name Description
    GameObject exitingVisitor

    OnVolumeDeactivated()

    Declaration
    protected override void OnVolumeDeactivated()
    In this article
    © 2026 Serenity. All Rights Reserved