Unity Background Scrolling First we have to add a background to our scene as a sprite. We then have to make a new script for our background we will call this ScrollSpeed. We add a public class variable using “public float” and call it “scrollSpeed = 10”. We then added the code “transform.Translate( new Vector3 (- 1, 0, 0) * Time .deltaTime * scrollSpeed);” in the update section this will move the background to the left when the game is played.
3
Embed
thomasbasford.files.wordpress.com … · Web viewNow we duplicate the Background by right clicking on it in the hierarchy and select duplicate this will make a copy of our back
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Unity Background ScrollingFirst we have to add a background to our scene as a sprite.
We then have to make a new script for our background we will call this ScrollSpeed.
We add a public class variable using “public float” and call it “scrollSpeed = 10”.
We then added the code “transform.Translate(new Vector3(-1, 0, 0) * Time.deltaTime * scrollSpeed);” in the update section this will move the background to the left when the game is played.
We add the script to the background so it will move to the left when played
Unity Background Scrolling
Now we duplicate the Background by right clicking on it in the hierarchy and select duplicate this will make a copy of our back ground.
We then move our background next to the original background on screen since it was duplicate the new background will already have the script.
Now when the game is run the new background will follow up right behind the previous background.
Now everything is good but eventually the second background will reach its end to fix this we have to make the background go back to starting position when it reaches then end of the screen.