Adjust the image size by changing the pixel per unit value so that the background image fits into the camera view. Steps to Create a Parallax effect Creating a Parallax layerĬreate an empty gameobject and name it as Parallax_layer.ĭrag and drop your first background image as child of the Parallax_layer. 2D Parallax Background scrolling for Unity by Vionix How to use the Parallax asset You can set it up with just a few clicks. It supports both horizontal and vertical background scrolling up to infinite layers. If you don’t like to write code and want a readymade solution for Parallax then you can buy our asset from itch (It will be available on Unity asset store soon). For the purpose of this tutorial, I have downloaded this free background from Unity asset store. You can download free images for Parallax background from Unity asset store. The number of layers can be anything more than one depending on your requirement. Your images should be created in layers and should look good stacked on top of each other. The first requirement for Parallax background are the images. This can be done by having a few layers of background and a simple script to move the background based on player or camera movement. If you use a virtual camera it does not listen to the positions properly if you have a Cinemachine Confiner attached.Parallax background is used in side scroller or vertical scroller games where you get the effect of depth and movement in background. When you drag your Camera to the script, drag your ACTUAL camera, not the virtual camera. You need to set your CinemachineBrain’s Update Method to “FixedUpdate” and Blend Update Method to “FixedUpdate” Using this script with Cinemachine works with as much as I’ve tested so far. The nice thing about this script is you don’t need to sort the Layers in order so if you come up with a new layer during development you don’t need to start over with the Parallax script. I use Sorting Groups attached to each object. You will need to control that with your own conventions. The layer objects are -not- locked to the depth of the objects. If you choose 0, it will appear the same as your regular stage. If you choose 1, it will lock the object to the camera’s position. Drag your layer object here and set it’s distance to the camera.ġ is the furthest you can be from the camera, and -1 is the closest you can be to the camera. If you’re following my ParallaxScenery convention, just name it the same as each layer. This can change from scene to scene, but for this example I’m going to do all 9 that I’ve been using.Įach element has a few things you need to do. The “Size” is how many layers you’re going to have in your scene. Next, let’s open up the array of Layers by clicking the arrow I’ve noticed 0.5 works nicely for me.ġ means the script will not affect the Y-axis.Ġ means the script will move the Y-axis the same as the X-axis. Vertical Restriction will restrict the parallax effect when your camera moves vertically. Head over to your inspector and it should look like this: Now, let’s set up the Parallax Script settings. If you created “ParallaxScenery” that’s where I put it, but you can throw it on your camera or any object you want. You only need this script on one object in the scene. I also attach a “Sorting Group” to each object correlating to the depth.Īgain, this step isn’t necessary, you can adapt the script to your project. I’ve found 9 different depths are all I need. Setting Up Backgrounds:įirst things first, you can setup your backgrounds however you like, this is just my preference.Ĭreate an object called “ParallaxScenery” and children of each “depth” of backgrounds and foregrounds. Parallax works with the standard Unity Camera and Cinemachine. Parallax is an easy way to make your backgrounds (and foregrounds!) move with your camera.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |