File tree Expand file tree Collapse file tree 5 files changed +27
-20
lines changed Expand file tree Collapse file tree 5 files changed +27
-20
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ MonoBehaviour:
270
270
m_Script : {fileID: 11500000, guid: ae79f9d99372a6b438f800230f434b9d, type: 3}
271
271
m_Name :
272
272
m_EditorClassIdentifier :
273
+ player : {fileID: 527830928}
273
274
scoreText : {fileID: 1474871343}
274
275
playButton : {fileID: 892178073}
275
276
gameOver : {fileID: 298509898}
Original file line number Diff line number Diff line change 3
3
4
4
public class GameManager : MonoBehaviour
5
5
{
6
- private Player player ;
7
- private Spawner spawner ;
6
+ public static GameManager Instance { get ; private set ; }
8
7
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 ;
13
15
14
16
private void Awake ( )
15
17
{
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
+ }
22
29
}
23
30
24
31
public void Play ( )
Original file line number Diff line number Diff line change 2
2
3
3
public class Parallax : MonoBehaviour
4
4
{
5
- private MeshRenderer meshRenderer ;
6
5
public float animationSpeed = 1f ;
6
+ private MeshRenderer meshRenderer ;
7
7
8
8
private void Awake ( )
9
9
{
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ public class Pipes : MonoBehaviour
4
4
{
5
5
public Transform top ;
6
6
public Transform bottom ;
7
-
8
7
public float speed = 5f ;
8
+
9
9
private float leftEdge ;
10
10
11
11
private void Start ( )
@@ -15,7 +15,7 @@ private void Start()
15
15
16
16
private void Update ( )
17
17
{
18
- transform . position += Vector3 . left * speed * Time . deltaTime ;
18
+ transform . position += speed * Time . deltaTime * Vector3 . left ;
19
19
20
20
if ( transform . position . x < leftEdge ) {
21
21
Destroy ( gameObject ) ;
Original file line number Diff line number Diff line change 2
2
3
3
public class Player : MonoBehaviour
4
4
{
5
- private SpriteRenderer spriteRenderer ;
6
5
public Sprite [ ] sprites ;
7
- private int spriteIndex ;
8
-
9
6
public float strength = 5f ;
10
7
public float gravity = - 9.81f ;
11
8
public float tilt = 5f ;
12
9
10
+ private SpriteRenderer spriteRenderer ;
13
11
private Vector3 direction ;
12
+ private int spriteIndex ;
14
13
15
14
private void Awake ( )
16
15
{
@@ -62,9 +61,9 @@ private void AnimateSprite()
62
61
private void OnTriggerEnter2D ( Collider2D other )
63
62
{
64
63
if ( other . gameObject . CompareTag ( "Obstacle" ) ) {
65
- FindObjectOfType < GameManager > ( ) . GameOver ( ) ;
64
+ GameManager . Instance . GameOver ( ) ;
66
65
} else if ( other . gameObject . CompareTag ( "Scoring" ) ) {
67
- FindObjectOfType < GameManager > ( ) . IncreaseScore ( ) ;
66
+ GameManager . Instance . IncreaseScore ( ) ;
68
67
}
69
68
}
70
69
You can’t perform that action at this time.
0 commit comments