![]() ![]() ![]() Now you can drag and drop the prefab to your scene as many times depending on the number of layers you want. Drag and drop the Parallax layer on to your project folder to make it into a prefab. Length=GetComponentInChildren().bounds.size Here is the final script using UnityEngine So, let’s update the code to get the distance moved by the camera and if its greater than the length of the image then we shift the startposition of the image by length of the image. So, we need to move the background after the camera has moved a distance greater than the length of the image. The only problem here is if your parallax background is not equal to one then at some point the background is going to disappear. Transform.position=startposition+relative_pos Vector3 relative_pos=your_*parallax_value Start is called before the first frame update Depending on the Parallax value the image will move with camera. We can just multiply the camera’s x position with Parallax value and add it to the start position of the image. So, we will get the camera, start position of the image and the Parallax value. We want this image to move relative to the camera speed. We can cover the blanks using these images. The reason we need three images is when you move the camera there will be a small blank before the image will replicate itself. Set the layer order in the sprite renderer.ĭuplicate the image two times and move them to the sides as shown in the image below.Īll the images will be children of Parallax_layer. 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 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. Parallax background is used in side scroller or vertical scroller games where you get the effect of depth and movement in background. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |