Advertisement
LeeMace

Repeat Background

Dec 2nd, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class RepeatBackground : MonoBehaviour
  6. {
  7.     private Vector3 startPos;
  8.     private float repeatWidth;
  9.  
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {//equals the postion of the background
  13.         startPos = transform.position;
  14.         repeatWidth = GetComponent<BoxCollider>().size.x / 2;
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {//when the backgound pos is less than 50 on the x it goes back to the start position
  20.         if (transform.position.x < startPos.x - repeatWidth)
  21.         {
  22.             transform.position = startPos;
  23.         }
  24.     }
  25. }
Tags: repeat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement