MCPity
MCPity Studio
Read-Only Demo

You're viewing a read-only demo

Sign up and upgrade to Pro to generate your own code with your Claude API key.

🚀

Space Runner

🎮 Unity · C#Active
Unity 2022.3 LTS
Connected
Prompt2h ago

Create a mobile-optimized HUD with score display, combo counter, health bar, and a stylized game over screen with restart button.

C#· 141 lines
1using UnityEngine;
2using UnityEngine.UI;
3using TMPro;
4using System.Collections;
5
6/// <summary>
7/// SpaceRunnerHUD - Mobile-optimized heads-up display with
8/// animated score, combo counter, health bar, and game-over overlay.
9/// </summary>
10public class SpaceRunnerHUD : MonoBehaviour
11{
12 [Header("Score Display")]
13 [SerializeField] private TextMeshProUGUI scoreText;
14 [SerializeField] private TextMeshProUGUI highScoreText;
15 [SerializeField] private float scoreLerpSpeed = 8f;
16
17 [Header("Combo Counter")]
18 [SerializeField] private TextMeshProUGUI comboText;
19 [SerializeField] private TextMeshProUGUI multiplierText;
20 [SerializeField] private Animator comboAnimator;
21 [SerializeField] private Image comboFillBar;
22
23 [Header("Health Bar")]
24 [SerializeField] private Image healthFill;
25 [SerializeField] private Image healthDamageFlash;
26 [SerializeField] private Gradient healthGradient;
27
28 [Header("Game Over")]
29 [SerializeField] private CanvasGroup gameOverPanel;
30 [SerializeField] private TextMeshProUGUI finalScoreText;
31 [SerializeField] private TextMeshProUGUI gameOverHighScoreText;
32 [SerializeField] private Button restartButton;
33 [SerializeField] private Button menuButton;
34 [SerializeField] private float fadeInDuration = 0.8f;
35
36 private int displayedScore;
37 private float targetHealthFill = 1f;
38
39 private void Start()
40 {
41 if (gameOverPanel != null)
42 {
43 gameOverPanel.alpha = 0f;
44 gameOverPanel.gameObject.SetActive(false);
45 }
46 restartButton?.onClick.AddListener(OnRestartClicked);
47 }
48
49 private void Update()
50 {
51 AnimateScore();
52 AnimateHealthBar();
53 }
54
55 public void UpdateScore(int score)
56 {
57 displayedScore = score;
58 }
59
60 public void UpdateCombo(int combo)
61 {
62 if (comboText != null)
63 {
64 comboText.text = combo > 0 ? $"x{combo}" : "";
65 comboText.gameObject.SetActive(combo > 0);
66 }
67 if (multiplierText != null && combo > 0)
68 {
69 float mult = 1f + (combo * 0.25f);
70 multiplierText.text = $"{mult:F1}x";
71 }
72 if (comboFillBar != null)
73 {
74 comboFillBar.fillAmount = combo / 10f;
75 }
76 comboAnimator?.SetTrigger("Pulse");
77 }
78
79 public void UpdateHealth(float normalized)
80 {
81 targetHealthFill = Mathf.Clamp01(normalized);
82 if (healthDamageFlash != null)
83 StartCoroutine(FlashDamage());
84 }
85
86 public void ShowGameOver(int finalScore, int highScore)
87 {
88 if (gameOverPanel == null) return;
89 gameOverPanel.gameObject.SetActive(true);
90 if (finalScoreText != null) finalScoreText.text = finalScore.ToString("N0");
91 if (gameOverHighScoreText != null) gameOverHighScoreText.text = $"Best: {highScore:N0}";
92 StartCoroutine(FadeInGameOver());
93 }
94
95 private void AnimateScore()
96 {
97 if (scoreText != null)
98 scoreText.text = displayedScore.ToString("N0");
99 }
100
101 private void AnimateHealthBar()
102 {
103 if (healthFill == null) return;
104 healthFill.fillAmount = Mathf.Lerp(healthFill.fillAmount, targetHealthFill, 6f * Time.deltaTime);
105 healthFill.color = healthGradient.Evaluate(healthFill.fillAmount);
106 }
107
108 private IEnumerator FlashDamage()
109 {
110 if (healthDamageFlash == null) yield break;
111 healthDamageFlash.color = new Color(1f, 0f, 0f, 0.5f);
112 float t = 0f;
113 while (t < 0.3f)
114 {
115 t += Time.deltaTime;
116 Color c = healthDamageFlash.color;
117 c.a = Mathf.Lerp(0.5f, 0f, t / 0.3f);
118 healthDamageFlash.color = c;
119 yield return null;
120 }
121 }
122
123 private IEnumerator FadeInGameOver()
124 {
125 float t = 0f;
126 while (t < fadeInDuration)
127 {
128 t += Time.unscaledDeltaTime;
129 gameOverPanel.alpha = t / fadeInDuration;
130 yield return null;
131 }
132 gameOverPanel.alpha = 1f;
133 }
134
135 private void OnRestartClicked()
136 {
137 UnityEngine.SceneManagement.SceneManager.LoadScene(
138 UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex
139 );
140 }
141}

Continue Building

🎮 Unity · C#·Claude Opus
BYOK Required