Singleton
tek sahne, tek kural, tek instance
GameManager.cs×
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
[SerializeField] private int playerScore;
[SerializeField] private int currentLevel;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
}
public void AddScore(int amount)
{
playerScore += amount;
Debug.Log($"Score: {playerScore}");
}
public void LoadNextLevel()
{
currentLevel++;
// Sahne yükleme mantığı
}
}