Advertisement
LeeMace

Parallax Layer

Feb 14th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. //put this onto the layer you want moving
  6. /*Allows the controller to move each layer based on the parallaxAmount!*/
  7.  
  8. public class ParallaxLayer : MonoBehaviour
  9. {
  10.     [Range(-1f, 1f)]
  11.     public float parallaxAmount; //The amount of parallax! 1 simulates being close to the camera, -1 simulates being very far from the camera!
  12.     [System.NonSerialized] public Vector3 newPosition;
  13.     private bool adjusted = false;
  14.  
  15.     public void MoveLayer(float positionChangeX, float positionChangeY)
  16.     {
  17.         newPosition = transform.localPosition;
  18.         newPosition.x -= positionChangeX * (-parallaxAmount * 40) * (Time.deltaTime);
  19.         newPosition.y -= positionChangeY * (-parallaxAmount * 40) * (Time.deltaTime);
  20.         transform.localPosition = newPosition;
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement