Guest User

Untitled

a guest
Jun 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LevelManager : MonoBehaviour
  6. {
  7. public GameObject currentCheckpoint;
  8.  
  9. private GameObject player;
  10. private GameObject[] fallingObjects;
  11. private Vector3[] initialPositions;
  12.  
  13.  
  14. void Start ()
  15. {
  16. player = GameObject.FindGameObjectWithTag("Player");
  17. fallingObjects = GameObject.FindGameObjectsWithTag("ObjectsThatFall");
  18. initialPositions = new Vector3[fallingObjects.Length];
  19.  
  20. SaveObjectsPosition();
  21. }
  22.  
  23. public void SaveObjectsPosition()
  24. {
  25. for (int i = 0; i < fallingObjects.Length; i++)
  26. initialPositions[i] = fallingObjects[i].transform.position;
  27. }
  28.  
  29. public void RespawnPlayer()
  30. {
  31. Debug.Log("Player Respawn");
  32.  
  33. RestartPlayerPosition();
  34.  
  35. RestartObjectsPosition();
  36.  
  37. }
  38.  
  39. public void RestartPlayerPosition()
  40. {
  41. player.transform.position = currentCheckpoint.transform.position;
  42. }
  43.  
  44. public void RestartObjectsPosition()
  45. {
  46. for (int i = 0; i < fallingObjects.Length; i++)
  47. fallingObjects[i].transform.position = initialPositions[i];
  48. }
  49. }
Add Comment
Please, Sign In to add comment