ketura

ParallaxBackground.cs

Sep 14th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ParallaxBackground : MonoBehaviour
  5. {
  6.   public Vector2 ParallaxFactor;
  7.  
  8.   public Camera MainCamera;
  9.  
  10.   private Vector2 lastPos;
  11.  
  12.     // Use this for initialization
  13.     void Start ()
  14.   {
  15.     lastPos = MainCamera.transform.position;
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update ()
  20.   {
  21.     Vector2 newPos = MainCamera.transform.position;
  22.     Vector2 diff = newPos - lastPos;
  23.  
  24.     transform.position += new Vector3(diff.x * ParallaxFactor.x, diff.y * ParallaxFactor.y);
  25.     lastPos = newPos;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment