Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GameController : MonoBehaviour {
  5. public GameObject Platform;
  6. public GameObject player;
  7. public GameObject Text;
  8.  
  9. public TimerController TimerScript;
  10. private Vector3 playerStartPosition;
  11. private Quaternion playerStartRotation;
  12. TimerController timerController;
  13. // Use this for initialization
  14. void Start ()
  15. {
  16. //get that TimerController
  17. timerController = GameObject.FindObjectOfType<TimerController>(); //use this if there's only one - otherwise find it by tag or gameobject name
  18.  
  19. //set the level's duration
  20. timerController.SetTimer(60f);
  21.  
  22. //start the timer ... if this is where you want it to start
  23. timerController.StartTimer();
  24.  
  25. playerStartPosition = player.transform.position;
  26. playerStartRotation = player.transform.rotation;
  27. Debug.Log("start pos: " + playerStartPosition.ToString());
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update ()
  32. {
  33. if (player.transform.position.y < -2f)
  34. ResetPlayer();
  35. }
  36.  
  37. void ResetPlayer()
  38. {
  39. Rigidbody playerRigid = gameObject.GetComponent<Rigidbody>();
  40. Debug.Log("start pos at reset: " + playerStartPosition.ToString());
  41. playerRigid.velocity = Vector3.zero;
  42. playerRigid.angularVelocity = Vector3.zero;
  43. player.transform.position = playerStartPosition;
  44. player.transform.rotation = playerStartRotation;
  45. Platform.transform.rotation = Quaternion.identity;
  46. Platform.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
  47. TimerScript.AddToTimer(-15f);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement