Italian_Style

GameManager x Giada

May 3rd, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using System;
  7.  
  8. public class NuovoGameManager : MonoBehaviour
  9. {
  10.     [SerializeField] GameObject cuore1;
  11.     [SerializeField] GameObject cuore2;
  12.     [SerializeField] GameObject cuore3;
  13.  
  14.     bool eLaPrimaVoltaCheEntriNelLivello = true;
  15.     //Il vero e proprio "Dio", visibile a tutti ed usabile da tutti
  16.     public static NuovoGameManager istanzaDellaClasseNuovoGameManager;
  17.  
  18.     public int vitaPlayer = 3;
  19.  
  20.     private void Start()
  21.     {
  22.         DontDestroyOnLoad(gameObject);
  23.     }
  24.  
  25.     private void OnEnable()
  26.     {
  27.         //Verifica se esiste un'altra istanza del GameManager nella scena
  28.         if (istanzaDellaClasseNuovoGameManager!= null && istanzaDellaClasseNuovoGameManager != this)
  29.             Destroy(gameObject);
  30.         else
  31.             istanzaDellaClasseNuovoGameManager = this;
  32.  
  33.         DontDestroyOnLoad(this);
  34.      
  35.         SceneManager.sceneLoaded += OnSceneLoaded;
  36.     }
  37.  
  38.     private void OnSceneLoaded(Scene scenaCorrente, LoadSceneMode arg1)
  39.     {
  40.         switch(scenaCorrente.name)
  41.         {
  42.             case "TestGiada":
  43.                 cuore1 = GameObject.FindGameObjectWithTag("Cuore1");
  44.                 cuore2 = GameObject.FindGameObjectWithTag("Cuore2");
  45.                 cuore3 = GameObject.FindGameObjectWithTag("Cuore3");
  46.  
  47.                 AggiornaCuori();
  48.                 break;
  49.         }
  50.     }
  51.  
  52.     public void AggiornaCuori()
  53.     {
  54.         if (eLaPrimaVoltaCheEntriNelLivello)
  55.             vitaPlayer = 3;
  56.        
  57.         else
  58.             vitaPlayer--;
  59.        
  60.         eLaPrimaVoltaCheEntriNelLivello = false;
  61.  
  62.         switch (vitaPlayer)
  63.         {
  64.             case 0:
  65.                 cuore1.SetActive(false);
  66.                 cuore2.SetActive(false);
  67.                 cuore3.SetActive(false);
  68.                 break;
  69.  
  70.             case 1:
  71.                 cuore1.SetActive(true);
  72.                 cuore2.SetActive(false);
  73.                 cuore3.SetActive(false);
  74.                 break;
  75.  
  76.             case 2:
  77.                 cuore1.SetActive(true);
  78.                 cuore2.SetActive(true);
  79.                 cuore3.SetActive(false);
  80.                 break;
  81.  
  82.             case 3:
  83.                 cuore1.SetActive(true);
  84.                 cuore2.SetActive(true);
  85.                 cuore3.SetActive(true);
  86.                 break;
  87.  
  88.             default:
  89.                 Debug.LogError("Errore, la vita non è normale");
  90.                 break;
  91.         }
  92.     }
  93. }
Add Comment
Please, Sign In to add comment