starOfWords/Assets/Scripts/ResultScene.cs
portakal ecb1c9edea Initial commit: Star of Words Unity project
Snapshot of the existing Unity 6 language-learning word game before any
refactoring. Adds Unity .gitignore and .gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 15:31:20 +03:00

117 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class ResultScene : MonoBehaviour
{
[Header("UI Texts")]
public TMP_Text scoreText;
public TMP_Text correctText;
public TMP_Text wrongText;
[Header("Buttons")]
public Button retryButton;
public Button levelMapButton;
public Button mainMenuButton;
[Header("Audio")]
public AudioSource audioSource;
public AudioClip clickSound;
private int score;
private int correct;
private int wrong;
private int level;
private int uiLangId;
// ============================================================
void Start()
{
// Uygulama dili (0=TR,1=EN,2=ES,3=DE,4=FR,5=PT)
uiLangId = PlayerPrefs.GetInt("AppLanguage", 0);
LoadSavedResults();
UpdateUI();
AssignButtons();
}
// ============================================================
// PlayerPrefs'ten sonuçları oku
// ============================================================
void LoadSavedResults()
{
score = PlayerPrefs.GetInt("Mod1Score", 0);
correct = PlayerPrefs.GetInt("Mod1Correct", 0);
wrong = PlayerPrefs.GetInt("Mod1Wrong", 0);
level = PlayerPrefs.GetInt("LastLevel", 1);
}
// ============================================================
// UI yazıları güncelle
// ============================================================
void UpdateUI()
{
string scoreWord = Local("score");
string correctWord = Local("correct");
string wrongWord = Local("wrong");
if (scoreText != null) scoreText.text = $"{scoreWord} {score}";
if (correctText != null) correctText.text = $"{correctWord} {correct}";
if (wrongText != null) wrongText.text = $"{wrongWord} {wrong}";
}
// ============================================================
// Basit lokalizasyon (6 dil)
// ============================================================
string Local(string key)
{
int L = Mathf.Clamp(uiLangId, 0, 5);
switch (key)
{
case "score":
return new[] { " " }[L];
case "correct":
return new[] { " " }[L];
case "wrong":
return new[] { " " }[L];
}
return key;
}
// ============================================================
// Butonlar
// ============================================================
void AssignButtons()
{
if (retryButton != null)
retryButton.onClick.AddListener(() => { PlayClick(); Retry(); });
if (levelMapButton != null)
levelMapButton.onClick.AddListener(() => { PlayClick(); SceneManager.LoadScene("LevelMap"); });
if (mainMenuButton != null)
mainMenuButton.onClick.AddListener(() => { PlayClick(); SceneManager.LoadScene("Anamen"); });
}
void PlayClick()
{
if (audioSource != null && clickSound != null)
audioSource.PlayOneShot(clickSound);
}
void Retry()
{
// Eğer bütün leveller tek sahnede oynanıyorsa:
// SceneManager.LoadScene("GameScene");
// Eğer levellevel sahne varsa, isim formatına göre bunu değiştir:
// Örn: "GameScene_Level1", "GameScene_Level2"...
string sceneName = "GameScene";
SceneManager.LoadScene(sceneName);
}
}