Skip to content

Commit 2001529

Browse files
committed
Code cleanup
1 parent 1f339ae commit 2001529

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

Assets/Scenes/Flappy Bird.unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ MonoBehaviour:
270270
m_Script: {fileID: 11500000, guid: ae79f9d99372a6b438f800230f434b9d, type: 3}
271271
m_Name:
272272
m_EditorClassIdentifier:
273+
player: {fileID: 527830928}
273274
scoreText: {fileID: 1474871343}
274275
playButton: {fileID: 892178073}
275276
gameOver: {fileID: 298509898}

Assets/Scripts/GameManager.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@
33

44
public class GameManager : MonoBehaviour
55
{
6-
private Player player;
7-
private Spawner spawner;
6+
public static GameManager Instance { get; private set; }
87

9-
public Text scoreText;
10-
public GameObject playButton;
11-
public GameObject gameOver;
12-
public int score { get; private set; }
8+
[SerializeField] private Player player;
9+
[SerializeField] private Text scoreText;
10+
[SerializeField] private GameObject playButton;
11+
[SerializeField] private GameObject gameOver;
12+
13+
private int score;
14+
public int Score => score;
1315

1416
private void Awake()
1517
{
16-
Application.targetFrameRate = 60;
17-
18-
player = FindObjectOfType<Player>();
19-
spawner = FindObjectOfType<Spawner>();
20-
21-
Pause();
18+
if (Instance != null)
19+
{
20+
DestroyImmediate(gameObject);
21+
}
22+
else
23+
{
24+
Instance = this;
25+
Application.targetFrameRate = 60;
26+
DontDestroyOnLoad(gameObject);
27+
Pause();
28+
}
2229
}
2330

2431
public void Play()

Assets/Scripts/Parallax.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
public class Parallax : MonoBehaviour
44
{
5-
private MeshRenderer meshRenderer;
65
public float animationSpeed = 1f;
6+
private MeshRenderer meshRenderer;
77

88
private void Awake()
99
{

Assets/Scripts/Pipes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ public class Pipes : MonoBehaviour
44
{
55
public Transform top;
66
public Transform bottom;
7-
87
public float speed = 5f;
8+
99
private float leftEdge;
1010

1111
private void Start()
@@ -15,7 +15,7 @@ private void Start()
1515

1616
private void Update()
1717
{
18-
transform.position += Vector3.left * speed * Time.deltaTime;
18+
transform.position += speed * Time.deltaTime * Vector3.left;
1919

2020
if (transform.position.x < leftEdge) {
2121
Destroy(gameObject);

Assets/Scripts/Player.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
public class Player : MonoBehaviour
44
{
5-
private SpriteRenderer spriteRenderer;
65
public Sprite[] sprites;
7-
private int spriteIndex;
8-
96
public float strength = 5f;
107
public float gravity = -9.81f;
118
public float tilt = 5f;
129

10+
private SpriteRenderer spriteRenderer;
1311
private Vector3 direction;
12+
private int spriteIndex;
1413

1514
private void Awake()
1615
{
@@ -62,9 +61,9 @@ private void AnimateSprite()
6261
private void OnTriggerEnter2D(Collider2D other)
6362
{
6463
if (other.gameObject.CompareTag("Obstacle")) {
65-
FindObjectOfType<GameManager>().GameOver();
64+
GameManager.Instance.GameOver();
6665
} else if (other.gameObject.CompareTag("Scoring")) {
67-
FindObjectOfType<GameManager>().IncreaseScore();
66+
GameManager.Instance.IncreaseScore();
6867
}
6968
}
7069

0 commit comments

Comments
 (0)