Forum rules - please read before posting.

Access camera constraints via script

Just wondering if anyone knows how to access the camera constraints via script for a 2D project?

I'm trying to have a camera lock into a room until the player moves to the edge, then have the camera unlock and follow the player.

An alternative to this was to create two camera to switch between, however I'm going for a retro look and I have Snap to grid? enabled, which doesn't seem to affect cameras that are transitioning.

Comments

  • Which constraint field are you looking to access, exactly? The Lock? field in the "Horizontal movement" panel?

    See the GameCamera2D script's entry in the Scripting Guide here. The above field is controlled by the lockHorizontal property.

    To change it through script, you'd place something like this in a new C# script:

    public void UnlockCamera ()
    {
        GetComponent <AC.GameCamera2D>().lockHorizontal = false;
    }
    

    Attach that to the GameCamera2D you want to control, and you can then call the "UnlockCamera" function from the Object: Call event Action.

  • Ah, okay. Thanks!

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.