usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassLevelScrolling:MonoBehaviour{publicintupdateRate=1;publicTransformlongcat;publicTransformbackground;privateVector3initialBgPos;privatefloat[]backgroundSize;// Start is called before the first frame updatevoidStart(){ResizeBackground();}// Update is called once per framevoidUpdate(){}voidFixedUpdate(){MoveBackground();MoveLongcat();}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;}privatevoidMoveLongcat(){longcat.Translate(newVector2(0.1f*updateRate,0));}privatevoidMoveBackground(){if(background.position.x>-initialBgPos.x)background.Translate(newVector2(0.1f*updateRate,0));elsebackground.position=initialBgPos;}}