Advertisement
Placido_GDD

MVC ScoreManager

Feb 4th, 2022
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class ScoreKeeper : MonoBehaviour
  7. {
  8.     public int score;
  9.     public int cubesActive;
  10.     public int activeCubes;
  11.     public Text scoreTxt;
  12.     public Text activeCubesTxt;
  13.     public CubeDataContainer cubeDataContainer;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         cubeDataContainer = GameObject.Find("CubeDataHolder").GetComponent<CubeDataContainer>();
  18.  
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.         SetScore();
  25.         TallyActiveCubes();
  26.     }
  27.  
  28.     void TallyActiveCubes()
  29.     {
  30.         activeCubes = CountActiveCubes();
  31.     }
  32.  
  33.     private int CountActiveCubes()
  34.     {
  35.         for (int i = 0; i < cubeDataContainer.CubeList.Count; i++)
  36.         {
  37.             if (cubeDataContainer.CubeList[i].activeSelf == true)
  38.             {
  39.                 cubesActive++;
  40.             }
  41.         }
  42.         return cubesActive;
  43.     }
  44.     void SetScore()
  45.     {
  46.         activeCubesTxt.text = activeCubes.ToString();
  47.         scoreTxt.text = score.ToString();
  48.     }
  49.    
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement