Skip to content

Commit

Permalink
Merge pull request #4 from DKU-STUDY/main
Browse files Browse the repository at this point in the history
Change the score outside the class using static.
  • Loading branch information
Jaewon0702 authored Nov 11, 2022
2 parents 72fb33f + 331e556 commit 969959b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Movement/BestScore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BestScore : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Text>().text = "Best Score: " + Score.bestScore;
}

// Update is called once per frame
}
9 changes: 9 additions & 0 deletions Movement/BirdJump.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections; //python의 import == using
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class BirdJump : MonoBehaviour
{
Expand All @@ -18,8 +19,16 @@ void Update()
{
if(Input.GetMouseButtonDown(0))
{
GetComponent<AudioSource>().Play(); // 점프할 때마다 소리 출력
rb.velocity = Vector2.up * jumpPower; //(0,1)*3, Vector3면 3차원(x,y,z), 3만큼 힘을 받아서 점프

}
}

private void OnCollisionEnter2D(Collision2D other) { //물체가 서로 부딪혔을 때 {}안의 내용을 실행
if(Score.score > Score.bestScore){
Score.bestScore = Score.score;
}
SceneManager.LoadScene("GameOverScene"); // 새가 물체에 부딪혀서 GameOverScene으로 전환
}
}
14 changes: 14 additions & 0 deletions Movement/CurrentScore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CurrentScore : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Text>().text = "Score: " + Score.score.ToString();
}

}
13 changes: 13 additions & 0 deletions Movement/Replay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Replay : MonoBehaviour
{

public void ReplayGame()
{
SceneManager.LoadScene("PlayScene");
}
}
23 changes: 23 additions & 0 deletions Movement/Score.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Score : MonoBehaviour
{
public static int score = 0; //static을 붙이면 class 밖에서도 score를 관리할 수 있다!

public static int bestScore = 0;

// Start is called before the first frame update
void Start()
{
score = 0;
}

// Update is called once per frame
void Update()
{
GetComponent<Text>().text = score.ToString();
}
}
10 changes: 10 additions & 0 deletions Movement/ScoreUp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScoreUp : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D other) {
Score.score++;
}
}
Binary file added Movement/flap.wav
Binary file not shown.

0 comments on commit 969959b

Please sign in to comment.