usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassLevelScrolling:MonoBehaviour{publicintUpdateRate=-5;publicList<Transform>Obstacles;publicTransformBackground;privateVector3initialBgPos;privatefloat[]backgroundSize;// Start is called before the first frame updatevoidStart(){ResizeBackground();}// Update is called once per framevoidUpdate(){}voidFixedUpdate(){MoveBackground();MoveObstacles();}privatevoidResizeBackground(){varsr=Background.GetComponent<SpriteRenderer>();if(sr==null)return;Background.localScale=newVector3(1,1,1);varwidth=sr.sprite.bounds.size.x;varheight=sr.sprite.bounds.size.y;varworldScreenHeight=Camera.main.orthographicSize*2.0;varworldScreenWidth=worldScreenHeight/Screen.height*Screen.width;varfinalHeight=(float)(worldScreenHeight/height);varfinalWidth=(float)(worldScreenWidth/width);Background.localScale=newVector3(finalHeight,finalHeight,1);varviewportX=Camera.main.ViewportToWorldPoint(newVector3(0,1,0)).x;Background.position=newVector3(viewportX*-1,0,0);initialBgPos=Background.position;}privatevoidMoveObstacles(){foreach(varoinObstacles){o.Translate(0.01f*UpdateRate,0,0);}}privatevoidMoveBackground(){if(Background.position.x>-initialBgPos.x)Background.Translate(0.01f*UpdateRate,0,0);elseBackground.position=initialBgPos;}}