Guest User

Unity C# Level Script 2

a guest
Feb 5th, 2019
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1.     float startTime;
  2.     int numTreasures;
  3.     int collected = 0;
  4.     bool levelComplete = false;
  5.     GameObject player;
  6.     public float levelBottomY = -10.0f;
  7.  
  8.     void Start()
  9.     {
  10.         // Take note of level start time. Time.time is seconds since program startup
  11.         startTime = Time.time;
  12.         // Count treasures in level
  13.         GameObject[] treasureObjects = GameObject.FindGameObjectsWithTag("Treasure");
  14.         numTreasures = treasureObjects.Length;
  15.         // Store player game object, needed for falling check
  16.         player = GameObject.FindWithTag("Player");
  17.     }
  18.  
  19.     void Update()
  20.     {
  21.         // Destroy player gameobject if fallen below level. The player variable goes null automatically
  22.         if (player != null && player.transform.position.y < levelBottomY)
  23.         {
  24.             Destroy(player);
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment