Flapping Pig – Scrolling Background
Day 076 #100DaysOfCode
Day 040 #100DaysOfGameDev
- added Rigidbody2D component to Ground, set to Kinematic
- create new scrollSpeed public variable in GameControl script
- create new ScrollingObject script attached to Ground create variable to reference Rigidbody2D component info
- set velocity to the new scrollSpeed variable
- create a velocity = 0 stopstate for scrolling if gameOver occurs
- create 2nd instance of sky & ground backgrounds and position for seamless scrolling
- create new RepeatingBG script attached to Ground & Ground2
- create variable to reference BoxCollider2D component info
- create variable to store BoxCollider horizontal length
- create new function called RepositionBackground
- create new Vector2 called groundOffset to jump the background forward two times its horizontal length
- create an Update check to see if Ground is off-screen, then call function RepositionBackground to jump it behind Ground2 to keep things moving endlessly