Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. public void Move(bool left,bool right, bool crouch, bool jump)
  2. {
  3.  
  4. if (right) {
  5. switch (forwardDirection) {
  6. case 1:
  7. m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
  8. break;
  9. case 2:
  10. m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
  11. break;
  12. case 3:
  13. m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
  14. break;
  15. case 4:
  16. m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
  17. break;
  18. }
  19.  
  20. } else if (left) {
  21. switch (forwardDirection) {
  22. case 1:
  23. m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
  24. break;
  25. case 2:
  26. m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
  27. break;
  28. case 3:
  29. m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
  30. break;
  31. case 4:
  32. m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
  33. break;
  34. }
  35. } else {
  36. switch (forwardDirection) {
  37. case 1:
  38. m_Rigidbody.velocity = new Vector3 (0f, 0f, 10f);
  39. break;
  40. case 2:
  41. m_Rigidbody.velocity = new Vector3 (10f, 0f, 0f);
  42. break;
  43. case 3:
  44. m_Rigidbody.velocity = new Vector3 (-10f, 0f, 0f);
  45. break;
  46. case 4:
  47. m_Rigidbody.velocity = new Vector3 (0f, 0f, -10f);
  48. break;
  49. }
  50.  
  51. }
  52. if (crouch && m_Animator.GetCurrentAnimatorStateInfo (0).IsName ("Run")) {
  53. m_Crouching=true;
  54. }else{
  55. m_Crouching=false;
  56. }
  57. CheckGroundStatus ();
  58.  
  59. if (!turn) {
  60. UpdateAnimator (jump);
  61. } else {
  62. if(right)
  63. {
  64. turn=false;
  65. Vector3 temp=transform.rotation.eulerAngles;
  66. if(temp.y<269f){
  67. temp.y=temp.y+90f; }
  68. else {
  69. temp.y=0;
  70. }
  71. transform.eulerAngles = temp;
  72. switch (forwardDirection) {
  73. case 1:
  74. forwardDirection=2;
  75.  
  76. break;
  77. case 2:
  78. forwardDirection=4;
  79.  
  80. break;
  81. case 3:
  82. forwardDirection=1;
  83.  
  84.  
  85. break;
  86. case 4:
  87. forwardDirection=3;
  88.  
  89. break;
  90. }
  91. }else if(left){
  92. turn=false;
  93. Vector3 temp=transform.rotation.eulerAngles;
  94. if(temp.y>-269f){
  95. temp.y=temp.y-90f; }
  96. else {
  97. temp.y=0;
  98. }
  99. transform.eulerAngles = temp;
  100. switch (forwardDirection) {
  101. case 1:
  102. forwardDirection=3;
  103.  
  104. break;
  105. case 2:
  106. forwardDirection=1;
  107.  
  108. break;
  109. case 3:
  110. forwardDirection=4;
  111.  
  112.  
  113. break;
  114. case 4:
  115. forwardDirection=2;
  116.  
  117. break;
  118. }
  119. }
  120.  
  121. }
  122. right = false;
  123. left = false;
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130. void UpdateAnimator(bool jump)
  131. {
  132.  
  133. if (jump) {
  134. m_Animator.SetBool ("Jump", true);
  135.  
  136. } else {
  137. m_Animator.SetBool ("Jump", false);
  138. }
  139.  
  140.  
  141.  
  142. if (m_Crouching) {
  143. m_Animator.SetBool ("Crouch", true);
  144. count = 0;
  145. }
  146. else {
  147. count +=1;
  148. if(count>100)
  149. m_Animator.SetBool ("Crouch", false);
  150. }
  151.  
  152. }
  153.  
  154.  
  155.  
  156. public void OnAnimatorMove()
  157. {
  158.  
  159. if (m_IsGrounded && Time.deltaTime > 0)
  160. {
  161. Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime;
  162.  
  163. // we preserve the existing y part of the current velocity.
  164. v.y = m_Rigidbody.velocity.y;
  165. m_Rigidbody.velocity = v;
  166. }
  167. }
  168.  
  169. public void setTurn(bool t){
  170. turn = t;
  171. }
  172.  
  173. void Start () {
  174. Vector3 angles = transform.eulerAngles;
  175. x = angles.x;
  176. y = angles.y;
  177. }
  178.  
  179. void LateUpdate () {
  180. if(!target)
  181. return;
  182.  
  183. y = target.eulerAngles.y;
  184.  
  185.  
  186. // ROTATE CAMERA:
  187. Quaternion rotation = Quaternion.Euler (x, y, 0);
  188. transform.rotation = rotation;
  189.  
  190. // POSITION CAMERA:
  191.  
  192. transform.position = target.position - (rotation * Vector3.forward * distance + new Vector3(0,-targetHeight,0));
  193.  
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement