🔥 10/21 월요일 목표 🔥
🔎 베스트 스코어 저장하기
🔎 남은 프로젝트 진행 및 PPT완성하기
10:00 팀프로젝트진행
12:00 수준별 꾸준 실습
16:00 수준별 꾸준 실습 UI특강
UIManager Script작성
public class UIManager : MonoBehaviour
{
public static UIManager instance;
[SerializeField] private GameObject gameOverCanvas;
[SerializeField] private TMP_Text curTxt;
[SerializeField] private TMP_Text bestTxt;
[SerializeField] private TMP_Text gameOverPanalcurTxt;
[SerializeField] private TMP_Text gameOverPanalbestTxt;
private int curScore;
private int bestScore;
public int CurScore
{
get { return curScore; }
set { curScore = value; }
}
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
return;
}
}
void Start()
{
gameOverCanvas.SetActive(false);
curTxt.text = $"현재스코어 : {curScore}";
bestScore = PlayerPrefs.GetInt("BestScore", 0);
bestTxt.text = $"베스트스코어 : {bestScore}";
}
void Update()
{
AddScore();
}
void AddScore()
{
curTxt.text = $"현재스코어 : {curScore}";
if (curScore > bestScore)
{
bestScore = curScore;
bestTxt.text = $"베스트스코어 : {bestScore}";
PlayerPrefs.SetInt("BestScore", bestScore);
PlayerPrefs.Save();
}
else
{
bestTxt.text = $"베스트스코어 : {bestScore}";
}
}
public void GameOver()
{
gameOverCanvas.SetActive(true);
gameOverPanalcurTxt.text = curTxt.text;
gameOverPanalbestTxt.text = bestTxt.text;
Time.timeScale = 0;
}
public void PressRestartBtn()
{
SceneManager.LoadScene("BrickOutGame");
}
}
Ball Script에서 Ball이 벽이나, 플레이어에 닿았을경우
TouchSoundClip을 오디오소스에 넣어주고, 플레이 시켜주는 간단한 코드구현
public AudioClip touchBlockClip;
private AudioSource touchedBlockSound;
private void Awake()
{
touchedBlockSound = GetComponent<AudioSource>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Wall")
{
touchedBlockSound.clip = touchBlockClip;
touchedBlockSound.Play();
}
else if (collision.gameObject.tag == "Player")
{
touchedBlockSound.clip = touchBlockClip;
touchedBlockSound.Play();
}
}
🔥 10/22 화요일 목표 🔥
🔎 팀프로젝트 제출하기
🔎 팀 프로젝트 PPT 발표하기
'Unity 내배캠 TIL' 카테고리의 다른 글
Unity 게임 개발 숙련 - (6주차2일) (0) | 2024.10.24 |
---|---|
Unity 게임 개발 숙련 - (6주차1일) (0) | 2024.10.24 |
Unity 게임 개발 입문 - 팀프로젝트 (5주차 4일) (1) | 2024.10.18 |
Unity - 게임 개발 입문 - 팀프로젝트 (5주차 3일) (0) | 2024.10.18 |
Unity 게임 개발 입문 - 팀프로젝트(5주차2일) (1) | 2024.10.18 |