Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using System;
- public class NuovoGameManager : MonoBehaviour
- {
- [SerializeField] GameObject cuore1;
- [SerializeField] GameObject cuore2;
- [SerializeField] GameObject cuore3;
- bool eLaPrimaVoltaCheEntriNelLivello = true;
- //Il vero e proprio "Dio", visibile a tutti ed usabile da tutti
- public static NuovoGameManager istanzaDellaClasseNuovoGameManager;
- public int vitaPlayer = 3;
- private void Start()
- {
- DontDestroyOnLoad(gameObject);
- }
- private void OnEnable()
- {
- //Verifica se esiste un'altra istanza del GameManager nella scena
- if (istanzaDellaClasseNuovoGameManager!= null && istanzaDellaClasseNuovoGameManager != this)
- Destroy(gameObject);
- else
- istanzaDellaClasseNuovoGameManager = this;
- DontDestroyOnLoad(this);
- SceneManager.sceneLoaded += OnSceneLoaded;
- }
- private void OnSceneLoaded(Scene scenaCorrente, LoadSceneMode arg1)
- {
- switch(scenaCorrente.name)
- {
- case "TestGiada":
- cuore1 = GameObject.FindGameObjectWithTag("Cuore1");
- cuore2 = GameObject.FindGameObjectWithTag("Cuore2");
- cuore3 = GameObject.FindGameObjectWithTag("Cuore3");
- AggiornaCuori();
- break;
- }
- }
- public void AggiornaCuori()
- {
- if (eLaPrimaVoltaCheEntriNelLivello)
- vitaPlayer = 3;
- else
- vitaPlayer--;
- eLaPrimaVoltaCheEntriNelLivello = false;
- switch (vitaPlayer)
- {
- case 0:
- cuore1.SetActive(false);
- cuore2.SetActive(false);
- cuore3.SetActive(false);
- break;
- case 1:
- cuore1.SetActive(true);
- cuore2.SetActive(false);
- cuore3.SetActive(false);
- break;
- case 2:
- cuore1.SetActive(true);
- cuore2.SetActive(true);
- cuore3.SetActive(false);
- break;
- case 3:
- cuore1.SetActive(true);
- cuore2.SetActive(true);
- cuore3.SetActive(true);
- break;
- default:
- Debug.LogError("Errore, la vita non è normale");
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment