Advertisement
BenTibnam

Scrolling 2D Background in Unity

Dec 19th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BackgroundScroll : MonoBehaviour
  6. {
  7.     private Material quadMaterial;
  8.     private Vector2 offset;
  9.  
  10.     [SerializeField] private int xVelocity;
  11.     [SerializeField] private int yVelocity;
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         quadMaterial = GetComponent<Renderer>().material;
  16.         offset = new Vector2(xVelocity, yVelocity);
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         quadMaterial.mainTextureOffset += offset * Time.deltaTime;
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement