Guest User

Untitled

a guest
Nov 6th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1.  
  2. var purpleenemy : GameObject;
  3.  
  4. var walkspeed : float = 0.8;
  5. var runspeed : float = 5;
  6. var ORwalkspeed :float = 0.8;
  7. var rotatespeed : float = 25.0;
  8. var character : GameObject;
  9. var jumpspeed : float = 1;
  10. var moveDirection : Vector3 = Vector3.zero;
  11. var gravity : float = 3.0;
  12. var pushpower: float = 3.0;
  13. var col :Collider;
  14. var watertexture : GUITexture;
  15. var mytransform : Transform;
  16. var driving = false;
  17. function Start ()
  18. {
  19. watertexture.enabled = false;
  20. driving = false;
  21.  
  22. }
  23.  
  24. function Update ()
  25. {
  26. //walk inputs
  27.  
  28. var controller: CharacterController = GetComponent(CharacterController);
  29.  
  30. if(controller.isGrounded)
  31. {
  32. if(driving == false)
  33. {
  34. transform.Rotate(0,Input.GetAxis("Horizontal") * rotatespeed * Time.smoothDeltaTime,0);
  35. moveDirection = Vector3(0,0,Input.GetAxis("Vertical"));
  36. moveDirection = transform.TransformDirection (moveDirection);
  37. moveDirection *= walkspeed;
  38.  
  39. //jump
  40. if(Input.GetKey(KeyCode.Space))
  41. {
  42. Jump();
  43. moveDirection.y = jumpspeed;
  44. }
  45. if(Input.GetKeyUp(KeyCode.LeftShift))
  46. {
  47. Runspeed = ORwalkspeed;
  48. }
  49. //move animations
  50. if(Input.GetKey(KeyCode.W))
  51. {
  52. Walk();
  53. }
  54.  
  55. if(Input.GetKey(KeyCode.S))
  56. {
  57. WalkBackWards();
  58. }
  59. if(Input.GetKeyUp(KeyCode.W))
  60. {
  61. Idle();
  62. }
  63. if(Input.GetKeyUp(KeyCode.S))
  64. {
  65. Idle();
  66. }
  67.  
  68.  
  69. if(Input.GetKey(KeyCode.LeftShift))
  70. {
  71. Idle();
  72. }
  73. }
  74. }
  75. if(!controller.isGrounded)
  76. {
  77.  
  78. }
  79.  
  80. controller.Move(moveDirection * Time.deltaTime);
  81. moveDirection.y -= gravity * Time.deltaTime;
  82.  
  83. if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
  84. {
  85. Run();
  86. walkspeed = runspeed;
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. //attack inputs
  95. if(Input.GetKeyDown(KeyCode.Mouse1))
  96. {
  97. R_punch();
  98. }
  99.  
  100. if(Input.GetKeyDown(KeyCode.Mouse0))
  101. {
  102. L_punch();
  103. }
  104.  
  105. }
  106.  
  107. //push
  108. function OnControllerColliderHit(hit:ControllerColliderHit)
  109. {
  110. if(hit.gameObject.tag == "bunny")
  111. {
  112. hit.rigidbody.AddForce(mytransform.forward * pushpower);
  113.  
  114. }
  115. if(hit.gameObject.tag == "enemy")
  116. {
  117. hit.rigidbody.AddForce(transform.forward * pushpower);
  118. }
  119. }
  120.  
  121.  
  122. //run/walk/idle animations
  123.  
  124. function Walk()
  125. {
  126. animation["walk"].speed = 3;
  127. animation["walk"].wrapMode = WrapMode.Loop;
  128. animation.CrossFade("walk");
  129. }
  130. function WalkBackWards()
  131. {
  132. animation["walk"].speed = -3;
  133. animation["walk"].wrapMode = WrapMode.Loop;
  134. animation.CrossFade("walk");
  135. }
  136. function Idle()
  137. {
  138. animation["Idle"].speed = 1;
  139. animation["Idle"].wrapMode = WrapMode.Loop;
  140. animation.CrossFade("Idle");
  141. }
  142.  
  143. function Jump()
  144. {
  145. animation["jump"].speed = 1;
  146. animation.CrossFade("jump");
  147. }
  148.  
  149.  
  150. function Run()
  151. {
  152. animation["run"].speed = 3;
  153. animation["run"].wrapMode = WrapMode.Loop;
  154. animation.CrossFade("run");
  155. }
  156.  
  157. //attack animations
  158.  
  159. function R_punch()
  160. {
  161. animation["right_attack_1"].speed = 8;
  162. print(animation["right_attack_1"].length);
  163. animation.CrossFade("right_attack_1");
  164. }
  165.  
  166. function L_punch()
  167. {
  168. animation["left_attack_1"].speed = 8;
  169. print(animation["left_attack_1"].length);
  170. animation.CrossFade("left_attack_1");
  171. }
  172. function L_punchB()
  173. {
  174. animation["left_attack_1"].speed = -4;
  175. print(animation["left__1"].length);
  176. animation.CrossFade("left_attack_1");
  177. }
  178.  
  179.  
  180. //ontriggerenter for water gui texture
  181. function OnTriggerEnter(other:Collider)
  182. {
  183. if(other.gameObject.tag == "waterbox")
  184. {
  185. watertexture.enabled = true;
  186. }
  187. if(other.gameObject.tag == "enemycheckpoint1")
  188. {
  189.  
  190. purpleenemy.GetComponent("purple enemy AI").disableobject = false;
  191. Debug.Log("disable object = false");
  192.  
  193. }
  194. }
  195. function OnTriggerExit(other:Collider)
  196. {
  197. if(other.gameObject.tag == "waterbox")
  198. {
  199. watertexture.enabled = false;
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment