How can I find the width of a scene?

I have a 2d sidescrolling game with a lot of different sized scenes. I am movint the camera horizontally along the scene until the end, but now I have to hardcode the end at which the camera should stop moving.

I would like to calculate the horizontal width of the current scene (not screen/window) to know when the camera should stop. I guess I could place an object at then end, and then use “onBecameVisible” to stop the camera, but is there a way to just get the width of the scene by code?

I can’t find scene.size in the docs :slight_smile:

Ha, I was thinking to suggest the object with on became visible when I first saw this thread, and then you even mentioned it in your post :slight_smile: I think that would be the easiest.

There is no such method. You could use some distance near the beginning and end to calculate, but honestly the on became visible sounds a lot easier (or in a way, almost the same).

The new Cinemachine is your friend in situations like this :slight_smile: You can use it to automatically track your player and you can provide it with a trigger collider that outlines your scene. Once the camera reaches the outline it will stop following.

It’s very nice and easy to use!