usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassLevelScrolling:MonoBehaviour{publicintUpdateRate=-5;publicList<GameObject>Obstacles;publicTransformBackground;privateVector3initialBgPos;privatefloat[]backgroundSize;// Start is called before the first frame updatevoidStart(){ResizeBackground();}// Update is called once per framevoidUpdate(){}voidFixedUpdate(){MoveBackground();MoveObstacles();DestroyObstacles();}voidResizeBackground(){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;}voidMoveObstacles(){for(inti=0;i<Obstacles.Count;i++){Obstacles[i].transform.Translate(0.01f*UpdateRate,0,0);}}voidDestroyObstacles(){if(Obstacles[0].transform.position.x<-30){Destroy(Obstacles[0]);Obstacles.RemoveAt(0);}}voidMoveBackground(){if(Background.position.x>-initialBgPos.x)Background.Translate(0.01f*UpdateRate,0,0);elseBackground.position=initialBgPos;}}