728x90
반응형

일일 목표점수 연동
![]() |
![]() |
- 팝업 화면 점수와 인게임 점수 연동
- 일일 목표점수 미달성시 Color.red, 달성시 Color.green
일일 목표점수 매핑
// DailyScore.cs
public static Dictionary<string, string> ScoreList = new()
{
{"1일", "124"},
{"2일", "351"},
{"3일", "674"},
{"4일", "595"},
{"5일", "803"},
{"6일", "616"},
{"7일", "845"},
{"8일", "937"},
{"9일", "290"},
{"10일", "533"},
{"11일", "741"},
{"12일", "588"},
{"13일", "918"},
{"14일", "446"},
{"15일", "576"},
{"16일", "629"},
{"17일", "821"},
{"18일", "887"},
{"19일", "463"},
{"20일", "222"},
{"21일", "746"},
{"22일", "517"},
{"23일", "439"},
{"24일", "908"},
{"25일", "564"},
{"26일", "366"},
{"27일", "953"},
{"28일", "813"},
{"29일", "974"},
{"30일", "432"},
{"31일", "999"},
};
- 1일 ~ 31일 각 도전할 목표점수 매핑
일일점수 주간점수 월간점수 통산점수 구현
- 각 점수 구현과 갱신 및 기간 별 초기화 적용
// boardManager.cs
public string SetHighScore()
{
int bestScore = PlayerPrefs.GetInt("bestScore", 0);
int TodayScore = PlayerPrefs.GetInt("TodayScore", 0);
int WeeklyScore = PlayerPrefs.GetInt("WeeklyScore", 0);
int MonthScore = PlayerPrefs.GetInt("MonthScore", 0);
if (score > bestScore)
{
PlayerPrefs.SetInt("bestScore", score);
PlayerPrefs.SetInt("MonthScore", score);
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "best";
}
if (score > MonthScore)
{
PlayerPrefs.SetInt("MonthScore", score);
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "Month";
}
if (score > WeeklyScore)
{
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "Weekly";
}
if (score > TodayScore)
{
PlayerPrefs.SetInt("TodayScore", score);
return "Today";
}
return "GameOver";
}
// GameHUB.cs
public void ShowGameOverUI(int score, string isNewRecord)
{
gameOverGroup.SetActive(true);
finalScoreText.text = score.ToString();
scoreText.gameObject.SetActive(false);
WeeklyScore.gameObject.SetActive(false);
Daily.SetActive(false);
BackBtn.SetActive(false);
ShapesPanel.SetActive(false);
if (isNewRecord != "GameOver") NewRecordText.gameObject.SetActive(true);
switch (isNewRecord)
{
case "best":
NewRecordText.text = "통산 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Month":
NewRecordText.text = "월간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Weekly":
NewRecordText.text = "주간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Today":
NewRecordText.text = "일간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
default:
GameOverText.gameObject.SetActive(true);
break;
}
Transform Scores = gameOverGroup.transform.Find("Scores").gameObject.transform;
Text Today = Scores.GetChild(2).GetChild(1).GetComponent<Text>();
Text Weekly = Scores.GetChild(3).GetChild(1).GetComponent<Text>();
Text Month = Scores.GetChild(4).GetChild(1).GetComponent<Text>();
Text Total = Scores.GetChild(5).GetChild(1).GetComponent<Text>();
Today.text = PlayerPrefs.GetInt("TodayScore", 0).ToString();
Weekly.text = PlayerPrefs.GetInt("WeeklyScore", 0).ToString();
Month.text = PlayerPrefs.GetInt("MonthScore", 0).ToString();
Total.text = PlayerPrefs.GetInt("bestScore", 0).ToString();
for (int i = 0; i < BoardPanel.childCount; i++)
{
BoardPanel.GetChild(i).GetComponent<SpriteRenderer>().sortingOrder = 0;
}
/* if (isNewRecord == "best")
{
NewRecordText.gameObject.SetActive(true);
GameOverText.gameObject.SetActive(false);
}*/
//gameOverGroup.transform.Find("New Record Text").gameObject.SetActive(isNewRecord);
int PlayCount = PlayerPrefs.GetInt("PlayCount", 0);
PlayerPrefs.SetInt("PlayCount", ++PlayCount);
}
각 점수 및 플레이 횟수 초기화
// DatatimeManager.cs
public class DatatimeManager : MonoBehaviour
{
// 날짜관련 스트립트
public Text TodayText;
private readonly string Today = DateTime.Now.ToString("M월 d일");
private void Awake()
{
TodayText.text = Today;
if (Today != PlayerPrefs.GetString("Today"))
{
if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) PlayerPrefs.SetInt("WeeklyScore", 0);
if (PlayerPrefs.GetString("Today").Substring(0, 2) != DateTime.Now.ToString("M월")) PlayerPrefs.SetInt("MonthScore", 0);
PlayerPrefs.SetString("Today", Today);
PlayerPrefs.SetInt("DailyChallenge", 0);
PlayerPrefs.SetInt("PlayCount", 0);
}
}
}
2번째 플레이부터 목표점수 팝업창 구현
- 게임오버시 PlayCount를 올려 일일 목표점수창 표시
- GameHUB.cs > ShowGameOverUI() 함수 실행시 PlayCount++;
- 재실행 혹은 게임 플레이시 Awake()에서 PlayCount를 검사하여 일일목표점수 표시
정산완료 진행 중
![]() |
![]() |
728x90
반응형
'개발일지 > TIL' 카테고리의 다른 글
[Unity Devcamp] 0210 개발일지 (0) | 2023.03.21 |
---|---|
[Unity Devcamp] 0208 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0206 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0201 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0131 개발일지 (0) | 2023.03.21 |
728x90
반응형

일일 목표점수 연동
![]() |
![]() |
- 팝업 화면 점수와 인게임 점수 연동
- 일일 목표점수 미달성시 Color.red, 달성시 Color.green
일일 목표점수 매핑
// DailyScore.cs
public static Dictionary<string, string> ScoreList = new()
{
{"1일", "124"},
{"2일", "351"},
{"3일", "674"},
{"4일", "595"},
{"5일", "803"},
{"6일", "616"},
{"7일", "845"},
{"8일", "937"},
{"9일", "290"},
{"10일", "533"},
{"11일", "741"},
{"12일", "588"},
{"13일", "918"},
{"14일", "446"},
{"15일", "576"},
{"16일", "629"},
{"17일", "821"},
{"18일", "887"},
{"19일", "463"},
{"20일", "222"},
{"21일", "746"},
{"22일", "517"},
{"23일", "439"},
{"24일", "908"},
{"25일", "564"},
{"26일", "366"},
{"27일", "953"},
{"28일", "813"},
{"29일", "974"},
{"30일", "432"},
{"31일", "999"},
};
- 1일 ~ 31일 각 도전할 목표점수 매핑
일일점수 주간점수 월간점수 통산점수 구현
- 각 점수 구현과 갱신 및 기간 별 초기화 적용
// boardManager.cs
public string SetHighScore()
{
int bestScore = PlayerPrefs.GetInt("bestScore", 0);
int TodayScore = PlayerPrefs.GetInt("TodayScore", 0);
int WeeklyScore = PlayerPrefs.GetInt("WeeklyScore", 0);
int MonthScore = PlayerPrefs.GetInt("MonthScore", 0);
if (score > bestScore)
{
PlayerPrefs.SetInt("bestScore", score);
PlayerPrefs.SetInt("MonthScore", score);
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "best";
}
if (score > MonthScore)
{
PlayerPrefs.SetInt("MonthScore", score);
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "Month";
}
if (score > WeeklyScore)
{
PlayerPrefs.SetInt("WeeklyScore", score);
PlayerPrefs.SetInt("TodayScore", score);
return "Weekly";
}
if (score > TodayScore)
{
PlayerPrefs.SetInt("TodayScore", score);
return "Today";
}
return "GameOver";
}
// GameHUB.cs
public void ShowGameOverUI(int score, string isNewRecord)
{
gameOverGroup.SetActive(true);
finalScoreText.text = score.ToString();
scoreText.gameObject.SetActive(false);
WeeklyScore.gameObject.SetActive(false);
Daily.SetActive(false);
BackBtn.SetActive(false);
ShapesPanel.SetActive(false);
if (isNewRecord != "GameOver") NewRecordText.gameObject.SetActive(true);
switch (isNewRecord)
{
case "best":
NewRecordText.text = "통산 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Month":
NewRecordText.text = "월간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Weekly":
NewRecordText.text = "주간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
case "Today":
NewRecordText.text = "일간 최고 점수 갱신";
NewRecordEffect.SetActive(true);
break;
default:
GameOverText.gameObject.SetActive(true);
break;
}
Transform Scores = gameOverGroup.transform.Find("Scores").gameObject.transform;
Text Today = Scores.GetChild(2).GetChild(1).GetComponent<Text>();
Text Weekly = Scores.GetChild(3).GetChild(1).GetComponent<Text>();
Text Month = Scores.GetChild(4).GetChild(1).GetComponent<Text>();
Text Total = Scores.GetChild(5).GetChild(1).GetComponent<Text>();
Today.text = PlayerPrefs.GetInt("TodayScore", 0).ToString();
Weekly.text = PlayerPrefs.GetInt("WeeklyScore", 0).ToString();
Month.text = PlayerPrefs.GetInt("MonthScore", 0).ToString();
Total.text = PlayerPrefs.GetInt("bestScore", 0).ToString();
for (int i = 0; i < BoardPanel.childCount; i++)
{
BoardPanel.GetChild(i).GetComponent<SpriteRenderer>().sortingOrder = 0;
}
/* if (isNewRecord == "best")
{
NewRecordText.gameObject.SetActive(true);
GameOverText.gameObject.SetActive(false);
}*/
//gameOverGroup.transform.Find("New Record Text").gameObject.SetActive(isNewRecord);
int PlayCount = PlayerPrefs.GetInt("PlayCount", 0);
PlayerPrefs.SetInt("PlayCount", ++PlayCount);
}
각 점수 및 플레이 횟수 초기화
// DatatimeManager.cs
public class DatatimeManager : MonoBehaviour
{
// 날짜관련 스트립트
public Text TodayText;
private readonly string Today = DateTime.Now.ToString("M월 d일");
private void Awake()
{
TodayText.text = Today;
if (Today != PlayerPrefs.GetString("Today"))
{
if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) PlayerPrefs.SetInt("WeeklyScore", 0);
if (PlayerPrefs.GetString("Today").Substring(0, 2) != DateTime.Now.ToString("M월")) PlayerPrefs.SetInt("MonthScore", 0);
PlayerPrefs.SetString("Today", Today);
PlayerPrefs.SetInt("DailyChallenge", 0);
PlayerPrefs.SetInt("PlayCount", 0);
}
}
}
2번째 플레이부터 목표점수 팝업창 구현
- 게임오버시 PlayCount를 올려 일일 목표점수창 표시
- GameHUB.cs > ShowGameOverUI() 함수 실행시 PlayCount++;
- 재실행 혹은 게임 플레이시 Awake()에서 PlayCount를 검사하여 일일목표점수 표시
정산완료 진행 중
![]() |
![]() |
728x90
반응형
'개발일지 > TIL' 카테고리의 다른 글
[Unity Devcamp] 0210 개발일지 (0) | 2023.03.21 |
---|---|
[Unity Devcamp] 0208 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0206 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0201 개발일지 (0) | 2023.03.21 |
[Unity Devcamp] 0131 개발일지 (0) | 2023.03.21 |