Coltmannnen

Untitled

Oct 21st, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Movement : MonoBehaviour
  5. {
  6.  
  7. Rigidbody rb;
  8. public GameObject Player;
  9. float speed = 0.05f;
  10. float JumpSpeed = 30f;
  11. bool PlayerNotJumping;
  12. Vector3 SpawnPoint = new Vector3(2.61f, 1f, 0.02f);
  13. public int HP = 5;
  14.  
  15. // Use this for initialization
  16. void Start()
  17. {
  18. rb = GetComponent<Rigidbody>();
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update()
  23. {
  24.  
  25. Controls();
  26.  
  27.  
  28. }
  29.  
  30. void Controls()
  31. {
  32.  
  33. Player = GameObject.FindGameObjectWithTag("Player");
  34.  
  35. if (HP <= 0)
  36.  
  37. {
  38. HP = 5;
  39. transform.position = SpawnPoint;
  40. }
  41.  
  42.  
  43. if (Input.GetKey(KeyCode.A))
  44. {
  45. transform.Translate(Vector3.left * speed);
  46. }
  47. if (Input.GetKey(KeyCode.D))
  48. {
  49. transform.Translate(Vector3.right * speed);
  50. }
  51.  
  52.  
  53. if(PlayerNotJumping == true)
  54. {
  55. if (Input.GetKeyDown(KeyCode.Space))
  56. {
  57.  
  58. Jump();
  59. }
  60. }
  61. }
  62.  
  63. void Jump()
  64. {
  65. rb.AddForce(Vector3.up * JumpSpeed);
  66. }
  67.  
  68. void OnCollisionEnter(Collision Other)
  69.  
  70. {
  71.  
  72. if(Other.gameObject.tag == "checkpoint")
  73. {
  74.  
  75. SpawnPoint = new Vector3(-37f, 0.99f, 0);
  76. }
  77.  
  78. if(Other.gameObject.tag == "Checkpoint2")
  79. {
  80. SpawnPoint = new Vector3(-86f, 0.99f, 0);
  81. }
  82.  
  83.  
  84. if (Other.gameObject.tag == "HolyGround")
  85. {
  86. PlayerNotJumping = true;
  87. }
  88.  
  89. if (Other.gameObject.tag == "UnholyGround")
  90. {
  91. HP -= 5;
  92. }
  93.  
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. void OnCollisionExit(Collision GroundCollide)
  105. {
  106. if(GroundCollide.gameObject.tag == "HolyGround")
  107. {
  108.  
  109.  
  110. PlayerNotJumping = false;
  111.  
  112. }
  113. }
  114.  
  115.  
  116.  
  117. }
Add Comment
Please, Sign In to add comment