Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System.Collections.Generic;
- public class TotalScoreView : MonoBehaviour
- {
- //этот класс должен быть на сцене только в одном экземпляре, иначе чревато
- private List<ScoreView> m_ScoreViewObjects;
- private Text m_TotalScore;
- private int m_TotalScoreCounter = 0;
- private void Awake()
- {
- m_ScoreViewObjects = new List<ScoreView> ();
- m_TotalScore = GetComponent<Text> ();
- }
- public void RegisterObserver(ScoreView observer)
- {
- observer.onDamageRecieve += OnDamageRecieve;
- m_ScoreViewObjects.Add (observer);
- }
- private void ShowScore(string value)
- {
- m_TotalScore.text = value;
- }
- private string ScoresToString(int value)
- {
- return string.Format ("Score: {0}", value);
- }
- private void OnDamageRecieve(int value)
- {
- m_TotalScoreCounter += value;
- ShowScore (ScoresToString (m_TotalScoreCounter));
- }
- private static TotalScoreView m_Instance;
- public static TotalScoreView Instance
- {
- get
- {
- if (m_Instance == null)
- {
- m_Instance = this;
- return m_Instance;
- }
- return m_Instance;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement