Programming-Design-Patterns.../Assets/Patterns_And_Principles/Patterns/The Singleton Pattern/SimpleSingleton/Script/SimpleSingleton.cs

41 lines
No EOL
977 B
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 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;
}
}
}