Skip to content

Commit 05c3e42

Browse files
committed
Add a new customizable gap property to pipes
1 parent 7207600 commit 05c3e42

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

Assets/Prefabs/Pipes.prefab

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Transform:
2626
m_PrefabAsset: {fileID: 0}
2727
m_GameObject: {fileID: 6053768793515663617}
2828
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
29-
m_LocalPosition: {x: 0, y: -4.5, z: 0}
29+
m_LocalPosition: {x: 0, y: -3.25, z: 0}
3030
m_LocalScale: {x: 1, y: 1, z: 1}
3131
m_Children: []
3232
m_Father: {fileID: 6053768794356161904}
@@ -134,7 +134,7 @@ Transform:
134134
m_PrefabAsset: {fileID: 0}
135135
m_GameObject: {fileID: 6053768794093319262}
136136
m_LocalRotation: {x: 1, y: -0, z: -0, w: 0}
137-
m_LocalPosition: {x: 0, y: 4.5, z: 0}
137+
m_LocalPosition: {x: 0, y: 3.25, z: 0}
138138
m_LocalScale: {x: 1, y: 1, z: 1}
139139
m_Children: []
140140
m_Father: {fileID: 6053768794356161904}
@@ -265,6 +265,7 @@ MonoBehaviour:
265265
top: {fileID: 6053768794093319263}
266266
bottom: {fileID: 6053768793515663630}
267267
speed: 5
268+
gap: 3
268269
--- !u!1 &7818968135391167135
269270
GameObject:
270271
m_ObjectHideFlags: 0

Assets/Scenes/Flappy Bird.unity

+3-1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ MonoBehaviour:
271271
m_Name:
272272
m_EditorClassIdentifier:
273273
player: {fileID: 527830928}
274+
spawner: {fileID: 2105631072}
274275
scoreText: {fileID: 1474871343}
275276
playButton: {fileID: 892178073}
276277
gameOver: {fileID: 298509898}
@@ -1111,7 +1112,8 @@ MonoBehaviour:
11111112
m_Script: {fileID: 11500000, guid: 374f7314a96d6a04d91aa0f1f644322b, type: 3}
11121113
m_Name:
11131114
m_EditorClassIdentifier:
1114-
prefab: {fileID: 6053768794356161907, guid: c1db09ac3ccffc742bbc907d839e8f3a, type: 3}
1115+
prefab: {fileID: -5845766125972383839, guid: c1db09ac3ccffc742bbc907d839e8f3a, type: 3}
11151116
spawnRate: 1
11161117
minHeight: -1
11171118
maxHeight: 2
1119+
verticalGap: 3

Assets/Scripts/GameManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class GameManager : MonoBehaviour
77
public static GameManager Instance { get; private set; }
88

99
[SerializeField] private Player player;
10+
[SerializeField] private Spawner spawner;
1011
[SerializeField] private Text scoreText;
1112
[SerializeField] private GameObject playButton;
1213
[SerializeField] private GameObject gameOver;

Assets/Scripts/Pipes.cs

+3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ public class Pipes : MonoBehaviour
55
public Transform top;
66
public Transform bottom;
77
public float speed = 5f;
8+
public float gap = 3f;
89

910
private float leftEdge;
1011

1112
private void Start()
1213
{
1314
leftEdge = Camera.main.ScreenToWorldPoint(Vector3.zero).x - 1f;
15+
top.position += Vector3.up * gap / 2;
16+
bottom.position += Vector3.down * gap / 2;
1417
}
1518

1619
private void Update()

Assets/Scripts/Spawner.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
public class Spawner : MonoBehaviour
44
{
5-
public GameObject prefab;
5+
public Pipes prefab;
66
public float spawnRate = 1f;
77
public float minHeight = -1f;
88
public float maxHeight = 2f;
9+
public float verticalGap = 3f;
910

1011
private void OnEnable()
1112
{
@@ -19,8 +20,9 @@ private void OnDisable()
1920

2021
private void Spawn()
2122
{
22-
GameObject pipes = Instantiate(prefab, transform.position, Quaternion.identity);
23+
Pipes pipes = Instantiate(prefab, transform.position, Quaternion.identity);
2324
pipes.transform.position += Vector3.up * Random.Range(minHeight, maxHeight);
25+
pipes.gap = verticalGap;
2426
}
2527

2628
}

0 commit comments

Comments
 (0)