Add mileage pickups and duty free concept

This commit is contained in:
jongjae0305
2026-06-22 09:19:19 +09:00
parent 1a7293ce6b
commit a043b19511
8 changed files with 372 additions and 3 deletions
+43 -1
View File
@@ -13,8 +13,16 @@ public class GameManager : MonoBehaviour {
private int score = 0; // 게임 점수
private int currentLife; // 현재 남은 목숨
private int stageMileage = 0; // 현재 플레이 중 획득한 마일리지
private int totalMileage = 0; // 누적 보유 마일리지
public int maxLife = 3; // 시작 목숨
public int initialMileage = 500; // 첫 시작시 지급할 초기 마일리지
public bool grantInitialMileage = true; // 초기 마일리지 지급 여부
public bool saveMileageImmediately = true; // 스테이지 정산 전까지는 획득 즉시 누적한다.
private const string TotalMileageKey = "UniRun.TotalMileage";
private const string InitialMileageGrantedKey = "UniRun.InitialMileageGranted";
// 게임의 스피드를 올리는 변수
public float gameSpeed = 1f;
@@ -44,6 +52,16 @@ public class GameManager : MonoBehaviour {
private void Start() {
currentLife = maxLife;
totalMileage = PlayerPrefs.GetInt(TotalMileageKey, 0);
if(grantInitialMileage && PlayerPrefs.GetInt(InitialMileageGrantedKey, 0) == 0)
{
totalMileage += initialMileage;
PlayerPrefs.SetInt(TotalMileageKey, totalMileage);
PlayerPrefs.SetInt(InitialMileageGrantedKey, 1);
PlayerPrefs.Save();
}
UpdateScoreUI();
}
@@ -75,6 +93,26 @@ public class GameManager : MonoBehaviour {
}
// 마일리지 토큰을 먹었을 때 호출되는 메서드
public void AddMileage(int amount) {
if(isGameover)
{
return;
}
stageMileage += amount;
score += Mathf.Max(1, amount / 10);
if(saveMileageImmediately)
{
totalMileage += amount;
PlayerPrefs.SetInt(TotalMileageKey, totalMileage);
PlayerPrefs.Save();
}
UpdateScoreUI();
}
// 플레이어가 장애물에 부딪혔을 때 목숨과 속도를 줄이는 메서드
public bool TakeDamage(int damage = 1) {
if(isGameover)
@@ -100,6 +138,10 @@ public class GameManager : MonoBehaviour {
}
private void UpdateScoreUI() {
scoreText.text = "Score : " + score + "\nLife : " + currentLife + "/" + maxLife + "\nSpeed : " + gameSpeed.ToString("0.0");
scoreText.text = "Score : " + score
+ "\nLife : " + currentLife + "/" + maxLife
+ "\nMileage : " + stageMileage
+ "\nTotal : " + totalMileage
+ "\nSpeed : " + gameSpeed.ToString("0.0");
}
}