Background Parallax Effect (C# Script Included)
Medieval Run Demo » Devlog
Unity 2D
I successfully incorporated a parallax effect into the background and made slight colour adjustments to enhance the forest theme. The parallax effect was achieved by creating a script that gains access to the camera's transform within the scene and then modifies the position of the game object (in this case, the different background image layers) using a corresponding multiplier. You can utilise the following script for this purpose:
Visit the game page here on itch.io and add it to your collection to stay up-to-date with updates and regular dev-logs.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ParallaxBackground : MonoBehaviour { private Transform cameraTransform; private Vector3 lastCameraPosition; [SerializeField] [Tooltip("Further Behind = Greater Multiplier")]float parallaxEffecMultiplier; private void Start() { cameraTransform = Camera.main.transform; lastCameraPosition = cameraTransform.position; } private void LateUpdate() { Vector3 deltaMovement = cameraTransform.position - lastCameraPosition; // Background Transform Position transform.position += deltaMovement * parallaxEffecMultiplier; // Reset Last Camera Position to Current Camera Positon lastCameraPosition = cameraTransform.position; } }
Medieval Run Demo
Status | Canceled |
Author | SolidCat |
Genre | Action, Platformer, Role Playing |
Tags | 2D, Action-Adventure, Arcade, Indie, Pixel Art, Side Scroller, Singleplayer, Unity |
Languages | English |
More posts
- Free Demo! (2 Boss Battles)Nov 07, 2023
- Night Foggy AtmosphereNov 02, 2023
Leave a comment
Log in with itch.io to leave a comment.