Advertisement
BloodknightStudios

Untitled

Nov 7th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3.  
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7.  
  8.  
  9. public class ScoreManger : MonoBehaviour
  10. {
  11. [SerializeField] int lives = 20; // number of enemies allowed to pass the level before failure
  12. public int gold = 200; // Sufficient starting capital to build the beginning set of towers
  13. public Text moneyText;
  14. public Text livesText;
  15.  
  16.  
  17. private void Start() {
  18. moneyText.text = "Gold:";
  19. livesText.text = "20";
  20.  
  21. DontDestroyOnLoad(gameObject);
  22. }
  23.  
  24.  
  25. public void ReduceLife(int val){
  26. lives -= val;
  27. if (lives <= 0){
  28. GameOver();
  29. }
  30. }
  31.  
  32.  
  33. void GameOver(){
  34. // Add menus or reload scene
  35. Debug.Log("Game Over");
  36. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
  37.  
  38. }
  39.  
  40.  
  41. private void Update() {
  42. moneyText.text = gold.ToString();
  43. livesText.text = lives.ToString();
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement