Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class Player_Health : MonoBehaviour
  7. {
  8.  
  9.     public int health;
  10.     public bool hasDied;
  11.  
  12.  
  13.     // Start is called before the first frame update
  14.     void Start() {
  15.         hasDied = false;      
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update() {
  20.             if (gameObject.transform.position.y > -7) {
  21.             health = 0;
  22.                 }
  23.             if (health == 0 && !hasDied) {
  24.             hasDied = true;
  25.             StartCoroutine ("Die");
  26.          }
  27.     }
  28.     IEnumerator Die () {
  29.         SceneManager.LoadScene ("SampleScene");
  30.         yield return null;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement