41 lines
No EOL
977 B
C#
41 lines
No EOL
977 B
C#
using System;
|
||
using UnityEngine;
|
||
|
||
namespace Patterns_And_Principles.Patterns.The_Singleton_Pattern.SimpleSingleton.Script
|
||
{
|
||
public class SimpleSingleton : MonoBehaviour
|
||
{
|
||
/*
|
||
* GameManager
|
||
* AudioManager
|
||
* InputManager
|
||
* SaveSystem
|
||
* EconomyManager
|
||
* Bu sistemler oyunumzda sadece bir tane olmasını bekleriz o yüzden singleton kullaniriz.
|
||
*/
|
||
public static SimpleSingleton Instance;
|
||
private int _coin = 0; // Test
|
||
|
||
private void Awake()
|
||
{
|
||
if (Instance != null && Instance != this)
|
||
{
|
||
Debug.Log("Destroyed: " + gameObject.name); // Test
|
||
Destroy(gameObject);
|
||
return;
|
||
}
|
||
|
||
Instance = this;
|
||
}
|
||
|
||
public void AddCoin(int amount)
|
||
{
|
||
_coin += amount;
|
||
}
|
||
|
||
public int GetCoin()
|
||
{
|
||
return _coin;
|
||
}
|
||
}
|
||
} |