maxhacker11

MenuParallax.cs

Jan 2nd, 2024
4,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | Source Code | 0 0
  1. using UnityEngine;
  2.  
  3. public class MenuParallax : MonoBehaviour
  4. {
  5.     public float offsetMultiplier = 1f;
  6.     public float smoothTime = .3f;
  7.  
  8.     private Vector2 startPosition;
  9.     private Vector3 velocity;
  10.  
  11.     private void Start()
  12.     {
  13.         startPosition = transform.position;
  14.     }
  15.  
  16.     private void Update()
  17.     {
  18.         Vector2 offset = Camera.main.ScreenToViewportPoint(Input.mousePosition);
  19.         transform.position = Vector3.SmoothDamp(transform.position, startPosition + (offset * offsetMultiplier), ref velocity, smoothTime);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment