Parallaxing seems like it should be built into Unity’s 2D workflow. Maybe by the time you are reading this it is? For everyone stuck in the now, I wanted to highlight a hidden, fantastic and lightweight parallaxing asset that’s not available on the Unity Asset store. This collection of 2 main scripts and an editor support script was written by the team that developed Light Fall. It’s easy to setup and fun to use.
David Dion-Paquet, of the Light Fall team, explains the reasons for developing this parallaxing system in a blog post called “Creating a parallax system in Unity3D is harder than it seems” over on Gamasutra. Even at 6 years old, Simple Parallax is the Goldilocks of Unity 2D parallaxing. It’s not too much, not too little…just right. Read the article and download the asset below and see my complete setup guide in the Setup Guide section below.
- Download the Simple Parallax asset from the Gamasutra article or from here and import it into your Unity Assets folder.
- Select your Main Camera and attach the ParallaxOption C# script to it.
- Check the Move Parallax option in the inspector under this newly added script.
- This option allows parallaxing to occur in the editor window, outside of play mode.
- Two convenience buttons are included with the ParallaxOption script, Save Position and Restore Position
- These buttons allow you to save and restore the main camera’s editor position so you can jump back and forth between two parallaxed positions.
- Add sprites to your scene for your various parallax layers. You can have as many as you like.
- Adjust the Order in Layer in the SpriteRenderer’s inspector settings so your images are displayed sensibly. (this doesn’t effect the parallax technically, just how the sprites sit on top of each other).
- For each sprite that you would like to enable parallaxing on, choose the sprites GameObject from the outliner and attach the ParallaxLayer C# script to it.
- You can parallax in X or Y by adding a value to the the Speed X or Speed Y inputs.
- These speeds will only be used when the camera is moving in the X or Y direction respectively
- A value of 0 is like not having the script attached at all. The camera will move by the image normally.
- A value of 1 is like parenting the sprite to the camera’s position. The sprite will appear to be fixed to the camera.
- 0 is for objects very close to the camera
- 1 is for objects very far away from the camera
- The Move in Reverse option is self explanatory
- Select the camera from the outliner while in editor mode and drag it around to test parallaxing.