Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7. public float speed;
  8. public float jumpForce;
  9. private float moveInput;
  10.  
  11.  
  12. private Rigidbody2D rb;
  13.  
  14. private bool facingRight = true;
  15.  
  16.  
  17. private bool isGrounded;
  18. public Transform groundCheck;
  19. public float checkRadius;
  20. public LayerMask whatIsGround;
  21.  
  22.  
  23. public int extraJump;
  24. public int extraJumpsValue;
  25.  
  26.  
  27. public Animator Animator;
  28.  
  29.  
  30. public bool TWasp = false;
  31. private bool cooldown = true;
  32. public float counter;
  33.  
  34.  
  35. // Use this for initialization
  36. void Start () {
  37. extraJump = extraJumpsValue;
  38. rb = GetComponent<Rigidbody2D>();
  39. }
  40.  
  41. void FixedUpdate()
  42. {
  43.  
  44. isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
  45.  
  46.  
  47.  
  48. moveInput = Input.GetAxis("Horizontal");
  49. rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
  50.  
  51. if(facingRight == false && moveInput > 0)
  52. {
  53. flip();
  54. } else if (facingRight == true && moveInput < 0) {
  55. flip();
  56. }
  57. }
  58.  
  59. void flip() {
  60.  
  61. facingRight = !facingRight;
  62. Vector3 Scaler = transform.localScale;
  63. Scaler.x *= -1;
  64. transform.localScale = Scaler;
  65.  
  66. }
  67. // Update is called once per frame
  68. void Update () {
  69.  
  70. Animator.SetFloat("speed", Mathf.Abs(moveInput));
  71.  
  72.  
  73.  
  74. if (isGrounded == true)
  75. {
  76. extraJump = extraJumpsValue;
  77. Animator.SetBool("isJumping", false);
  78. } else
  79. {
  80. Animator.SetBool("isJumping", true);
  81. }
  82.  
  83.  
  84. if(Input.GetKeyDown(KeyCode.UpArrow) && extraJump > 0 && cooldown == true)
  85. {
  86. rb.velocity = Vector2.up * jumpForce;
  87. extraJump--;
  88. } else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJump == 0 && isGrounded == true) {
  89. rb.velocity = Vector2.up * jumpForce;
  90. }
  91.  
  92.  
  93. if(Input.GetKeyDown(KeyCode.Space) && isGrounded == true && cooldown == true)
  94. {
  95. speed = 0;
  96. Animator.SetBool("Transforming", true);
  97. cooldown = false;
  98.  
  99. }
  100.  
  101. if (TWasp == true && cooldown == true)
  102. {
  103. speed = 80;
  104. extraJumpsValue = 1;
  105. Animator.SetBool("TState", true);
  106. } else if(TWasp == false && cooldown == true)
  107. {
  108. speed = 50;
  109. extraJumpsValue = 0;
  110. Animator.SetBool("TState", false);
  111. }
  112.  
  113. if (cooldown == false)
  114. {
  115. counter += Time.deltaTime;
  116. if(counter > 0.6)
  117. {
  118. cooldown = true;
  119. Animator.SetBool("Transforming", false);
  120. TWasp = !TWasp;
  121. counter = 0;
  122. }
  123. }
  124.  
  125. }
  126.  
  127.  
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement