Advertisement
LeeMace

game manager add lives and score

Nov 29th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GameManager : MonoBehaviour
  6. {
  7.     private int score = 0;
  8.     private int lives = 10;
  9.  
  10.     void Start()
  11.     {
  12.  
  13.     }
  14.  
  15.     void Update()
  16.     {
  17.  
  18.     }
  19.  
  20.     //shows game over when lives = 0
  21.     public void AddLives(int value)
  22.     {
  23.         lives += value;
  24.  
  25.         if (lives <= 0)
  26.         {
  27.             Debug.Log("Game Over");
  28.             lives = 0;
  29.         }
  30.         Debug.Log("Lives =" + lives);
  31.     }
  32.  
  33.     //adds score when player destroys animals
  34.     public void AddScore(int value)
  35.     {
  36.         score += value;
  37.         Debug.Log("Score =" + score);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement