Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //in game manager.cs
- //for lives UI
- public TextMeshProUGUI livesText;
- private int lives;
- public void UpdateLives(int livesToChange)
- {
- lives += livesToChange;
- livesText.text = "Lives " + lives;
- if(lives<= 0)
- {
- GameOver();
- }
- }
- public void StartGame(int difficulty)
- {
- //starting number of lives
- UpdateLives(5);
- }
- //In Target.cs script
- private GameManager gameManager;
- void Start()
- {
- gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();
- }
- //object hitting sensor destroys it
- //1 life is taekn away if object hits the sensor
- private void OnTriggerEnter(Collider other)
- {
- Destroy(gameObject);
- if (!gameObject.CompareTag("Bad"))
- {
- gameManager.UpdateLives(-1);
- if (gameManager.lives < 0)
- {
- gameManager.lives = 0;
- gameManager.UpdateLives(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement