Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ParallaxBackground : MonoBehaviour
- {
- public Vector2 ParallaxFactor;
- public Camera MainCamera;
- private Vector2 lastPos;
- // Use this for initialization
- void Start ()
- {
- lastPos = MainCamera.transform.position;
- }
- // Update is called once per frame
- void Update ()
- {
- Vector2 newPos = MainCamera.transform.position;
- Vector2 diff = newPos - lastPos;
- transform.position += new Vector3(diff.x * ParallaxFactor.x, diff.y * ParallaxFactor.y);
- lastPos = newPos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment