Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Moving_WASD : MonoBehaviour
  6. {
  7. public float speed = 0.1f;
  8.  
  9. public Vector3 inertiaVector;
  10.  
  11. public bool onLadder;
  12.  
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16.  
  17. }
  18.  
  19. // Update is called once per frame
  20. void Update()
  21. {
  22.  
  23. if(!GetComponent<Jumping>().inAir)
  24. {
  25. if ( Input.GetKey (KeyCode.W ) )
  26. {
  27. /if(!GetComponent<Jumping>().inAir)/ transform.position += transform.forward * speed;
  28. //else inertiaVector = transform.forward;
  29. }
  30.  
  31. if ( Input.GetKey (KeyCode.S ) )
  32. {
  33. /if(!GetComponent<Jumping>().inAir)/ transform.position -= transform.forward * speed;
  34. //else inertiaVector = -transform.forward;
  35. }
  36.  
  37. if ( Input.GetKey (KeyCode.D ) )
  38. {
  39. /if(!GetComponent<Jumping>().inAir)/ transform.position += transform.right * speed;
  40. //else inertiaVector = transform.right;
  41. }
  42.  
  43. if ( Input.GetKey (KeyCode.A ) )
  44. {
  45. /if(!GetComponent<Jumping>().inAir)/ transform.position -= transform.right * speed;
  46. //else inertiaVector = -transform.right;
  47. }
  48. }
  49.  
  50. }
  51. void OnTriggerStay (Collider ladder)
  52. {
  53. if(ladder.name == "Ladder")
  54. {
  55. /GetComponent<Player_WASD>()./onLadder = true;
  56. GetComponent<Jumping>().inAir = false;
  57.  
  58. if(!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Space))
  59. {
  60. GetComponent<Rigidbody>().isKinematic = true;
  61.  
  62. if(transform.position.y > ladder.GetComponent<Ladder>().b.position.y)
  63. {
  64. Vector3 temp = transform.position;
  65. temp.y = ladder.GetComponent<Ladder>().b.position.y;
  66. transform.position = temp;
  67. }
  68. if(transform.position.y < ladder.GetComponent<Ladder>().a.position.y)
  69. {
  70. Vector3 temp = transform.position;
  71. temp.y = ladder.GetComponent<Ladder>().a.position.y;
  72. transform.position = temp;
  73. }
  74.  
  75. if( ( transform.position.y <= ladder.GetComponent<Ladder>().b.position.y ) && ( transform.position.y >= ladder.GetComponent<Ladder>().a.position.y ) )
  76. {
  77. if(Input.GetKey(KeyCode.UpArrow)) transform.position += transform.up * speed;
  78. if(Input.GetKey(KeyCode.DownArrow)) transform.position -= transform.up * speed;
  79. }
  80. else
  81. {
  82. GetComponent<Rigidbody>().isKinematic = false;
  83. /GetComponent<Player_WASD>()./onLadder = false;
  84. }
  85. }
  86. }
  87. }
  88. else
  89. {
  90. GetComponent<Rigidbody>().isKinematic = false;
  91. /GetComponent<Player_WASD>()./onLadder = false;
  92. GetComponent<Jumping>().inAir = false;
  93. }
  94. }
  95. }
  96.  
  97. void OnTriggerExit (Collider ladder)
  98. {
  99. if(ladder.name == "Ladder") { GetComponent<Rigidbody>().isKinematic = false; /GetComponent<Player_WASD>()./onLadder = false; GetComponent<Jumping>().inAir = false;}
  100. }
  101.  
  102. }
  103. using System.Collections;
  104. using System.Collections.Generic;
  105. using UnityEngine;
  106.  
  107. public class Health : MonoBehaviour
  108. {
  109. public float health = 100;
  110.  
  111. public bool alive = true;
  112.  
  113. public void Update()
  114. {
  115.  
  116. if( health < 0)
  117. {
  118. health = 0;
  119. GetComponent<Renderer>().material.color = Color.red;
  120.  
  121. }
  122.  
  123. }
  124. }
  125. {
  126.  
  127. if( Input.GetKey(KeyCode.LeftControl))
  128. {
  129. Vector3 tempSize = transform.localScale;
  130.  
  131. if(Input.GetKey(KeyCode.LeftShift))
  132. tempSize.y = heightProne;
  133. else tempSize.y = heightCrouch;
  134.  
  135. transform.localScale = tempSize;
  136.  
  137. }
  138. else
  139. {
  140. //Vector3 tempSize = transform.localScale;
  141. //tempSize.y = height;
  142.  
  143. transform.localScale = heightVector;
  144. }
  145.  
  146. if (Physics.Raycast(transform.position, -transform.up, testValue) )
  147. {
  148. if ( Input.GetKeyDown (KeyCode.Space ) )
  149. {
  150. GetComponent<Rigidbody>().AddForce(transform.up * jumpForceNow);
  151. //GetComponent<Rigidbody>().AddForce(GetComponent<Moving_WASD>().inertiaVector * testValue2);
  152. //GetComponent<Moving_WASD>().inertiaVector = Vector3.zero;
  153. }
  154.  
  155. inAir = false;
  156. }
  157. else if(!GetComponent<Moving_WASD>().onLadder) inAir = true;
  158.  
  159.  
  160. }
  161. }
  162. using System.Collections;
  163. using System.Collections.Generic;
  164. using UnityEngine;
  165.  
  166. public class HitBox : MonoBehaviour
  167. {
  168. public GameObject owner;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement