Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Controller : MonoBehaviour {
  6.  
  7. public GameObject idle;
  8. public Transform forward;
  9. public Transform backwards;
  10. public Transform left;
  11. public Transform right;
  12. public Transform lf;
  13. public Transform rf;
  14. public Transform lb;
  15. public Transform rb;
  16. public float moveSpeed;
  17. public float walkSpeed = 2;
  18. public float runSpeed = 4;
  19. public float rotationSpeed = 90.0f;
  20. public bool running = false;
  21. public bool walking = false;
  22. public Animation anim;
  23. public string idleAnim = "Idle";
  24. public string walkAnim = "Walk";
  25. public string runAnim = "Run";
  26. public string atak = "attack";
  27. public string roll = "rolling";
  28. public GameObject rTrail;
  29. public GameObject hTrail;
  30. public GameObject collider;
  31. public Rigidbody rigidbody;
  32. public bool canInputMovement = true;
  33.  
  34. public bool cooldown;
  35. public bool rolling;
  36. public bool onGround;
  37.  
  38. // Use this for initialization
  39. void Start () {
  40. anim.Play(idleAnim);
  41. }
  42.  
  43. void OnTriggerEnter () {
  44. anim.Play(idleAnim);
  45. onGround = true;
  46. }
  47. void OnTriggerExit () {
  48. onGround = false;
  49. }
  50.  
  51. // Update is called once per frame
  52. void Update () {
  53.  
  54. if(Input.GetMouseButtonDown(0) && !cooldown){
  55. StartCoroutine(mandioca());
  56. }
  57. if(Input.GetKeyDown(KeyCode.Space) && !cooldown && onGround == true){
  58. rigidbody.velocity += 16 * Vector3.up;
  59. StartCoroutine(mandioca2());
  60. }
  61. if(Input.GetKeyDown(KeyCode.T) ){
  62. anim.Play("dance");
  63. }
  64. if(onGround == false){
  65. anim.Play("fall");
  66. }
  67.  
  68. if(canInputMovement){
  69.  
  70. if(Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)){
  71. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  72. idle.transform.rotation = forward.transform.rotation;
  73. }
  74. if(Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A)){
  75. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  76. idle.transform.rotation = backwards.transform.rotation;
  77. }
  78. if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W)){
  79. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  80. idle.transform.rotation = left.transform.rotation;
  81. }
  82. if(Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S)){
  83. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  84. idle.transform.rotation = right.transform.rotation;
  85. }
  86.  
  87.  
  88.  
  89. if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)){
  90. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  91. idle.transform.rotation = lf.transform.rotation;
  92. }
  93. if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)){
  94. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  95. idle.transform.rotation = rf.transform.rotation;
  96. }
  97. if(Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)){
  98. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  99. idle.transform.rotation = lb.transform.rotation;
  100. }
  101. if(Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)){
  102. transform.position += transform.forward * Time.deltaTime * moveSpeed;
  103. idle.transform.rotation = rb.transform.rotation;
  104. }
  105.  
  106.  
  107. //GetComponent<Rigidbody>().velocity = transform.forward * moveSpeed * movePlayer;
  108. }
  109. if(walking == true){
  110. moveSpeed = walkSpeed;
  111. }
  112. if(running == true){
  113. rTrail.SetActive(true);
  114. moveSpeed = runSpeed;
  115. }else{
  116. rTrail.SetActive(false);
  117. }
  118.  
  119. if(canInputMovement){
  120. //ANIMATIONS ==============================================
  121. //start_idlle_master
  122.  
  123. if(Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.LeftShift)){
  124. anim.CrossFade(idleAnim);
  125. }
  126.  
  127. if(!cooldown && Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift)){
  128. running = true;
  129. anim.CrossFade(runAnim);
  130. }else{
  131. running = false;
  132. }
  133.  
  134. //walk_forward
  135. if(!cooldown && Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftShift)){
  136. walking = true;
  137. anim.CrossFade(walkAnim);
  138. }else{
  139. walking = false;
  140. }
  141. }
  142.  
  143. }
  144.  
  145. public IEnumerator mandioca(){
  146. anim.Play(atak);
  147. cooldown = true;
  148. //canInputMovement = false;
  149. collider.SetActive(true);
  150. hTrail.SetActive(true);
  151. yield return new WaitForSeconds(0.25f);
  152. collider.SetActive(false);
  153. if(onGround == true && walking == true){
  154. anim.CrossFade(walkAnim);
  155. }
  156. if(onGround == true && walking == false){
  157. anim.CrossFade(idleAnim);
  158. }
  159. if(onGround == false){
  160. anim.Play("fall");
  161. }
  162. hTrail.SetActive(false);
  163. canInputMovement = true;
  164. cooldown = false;
  165. }
  166. public IEnumerator mandioca2(){
  167. cooldown = true;
  168. rolling = true;
  169. yield return new WaitForSeconds(1.1f);
  170. rolling = false;
  171. canInputMovement = true;
  172. cooldown = false;
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement