Flappy Pig – Obstacles, Score & Parallax
Day 077 #100DaysOfCode
Day 041 #100DaysOfGameDev
- place Wooden Post object and set to midground sorting layer
- give BoxCollider2D component to Wooden Post
- duplicate Wooden Post object to create a top and a bottom version
- group posts inside holder object
- assign BoxCollider2D component to Post holder object and set as trigger
- set trigger zone for Posts after gap in Wooden Posts to create a scoring zone
- add RigidBody2D component to Post holder and set to kinematic
- create new WoodenPosts script and add to Post holder object
![](https://i0.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17notepad_script_WoodenPosts.png?resize=608%2C182&ssl=1)
- add new public PigScored function to GameControl script
![](https://i0.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17notepad_script_GameControl_function_PigScore.png?resize=620%2C230&ssl=1)
- create private Score integer in GameControl
- create state in PigScored that disallows scoring if Pig is KO’d
- create score +1 condition for each set of Posts cleared
- add namespace UnityEngine.UI to GameControl to be able to allow UI score updating
- declare new public Text named scoreText to track scoring
- create score overlay to display on-screen within PigScored function
![](https://i2.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17Unity_Flappy-Pig_score.png?fit=800%2C378&ssl=1)
- in WoodenPosts script set trigger condition to check if collision entity is FlappyPig and call PigScored if true
- add ScrollingObject script to Posts
- turn Posts into a prefab for use in repeating obstacles
- created ParallaxRepeat script for sky background
![](https://i0.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17notepad_script_ParallaxRepeat.png?resize=800%2C386&ssl=1)
- created ParallaxScroll script for sky background
![](https://i0.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17notepad_script_ParallaxScroll.png?resize=800%2C309&ssl=1)
- separated Sky background from Ground and attached new Parallax scripts to it
- set new parallaxScroll speed for new Sky background velocity in GameControl
![](https://i0.wp.com/gamedev.sinwyrm.com/wp-content/uploads/2020/02/2020-02-17notepad_script_GameControl_parallax.png?resize=705%2C212&ssl=1)