117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|