Library of scripts for creating the parallax effect on UI elements in Unity.
<< How does it work | How to use | Install | Download >>
UI elements are usually displayed orthogonally, so it is impossible to create a parallax effect by moving and rotating the camera. However, no one is stopping us from moving and rotating UI objects in such a way as if the camera were moving, not the objects. Such a movement of UI objects gives a very realistic parallax effect.
The library uses an accelerometer, not a gyroscope, because an accelerometer is present on more devices than a gyroscope.
Firstly, you need to add component of the parallax effect on the scene - the UIParallaxEffect
script. It contains a set of UIParallaxLayer
objects, which is an array of different UI elements with its parallax settings.
Important! Component UIParallaxEffect
initialize and update automatically. If you want control UIParallaxEffect
by yourself, than set parametre AutoUpdate
to false and call methods Initialize()
and RefreshParallaxEffect()
in outer scripts.
Secondly, you must define each UIParallaxLayer
in the UIParallaxEffect
component. UIParallaxLayer
has several parameters that will be described below.
- ParallaxLayerName - layer name (for ease of display)
- ObjectsRect - array of RectTransform objects that belong to this layer
- PosXMultiplier - the value at which the X position in the anchoredPosition of the objects changes
- PosYMultiplier - the value at which the Y position in the anchoredPosition of the objects changes
- InterpolationSpeed - parallax speed, in other words, the speed at which layer objects move and rotate
- Download
UIParallaxEffect.unitypackage
and using UnityPackageManager. - The Unity Package Manager (UPM) is a new method to manage external packages. It keeps package contents separate from your main project files.
Modify your project's Packages/manifest.json file adding this line:
"com.lodza.uiparallax": "https://github.com/RodionLodza/UIParallaxLibary.git#package-branch"
To access classes inside of this package you will need to add a reference to com.lodza.fastpool.asmdef to your project's assembly definition file.