Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- public float speed;
- public float jumpForce;
- private float moveInput;
- private Rigidbody2D rb;
- private bool facingRight = true;
- private bool isGrounded;
- public Transform groundCheck;
- public float checkRadius;
- public LayerMask whatIsGround;
- public int extraJump;
- public int extraJumpsValue;
- public Animator Animator;
- public bool TWasp = false;
- private bool cooldown = true;
- public float counter;
- // Use this for initialization
- void Start () {
- extraJump = extraJumpsValue;
- rb = GetComponent<Rigidbody2D>();
- }
- void FixedUpdate()
- {
- isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
- moveInput = Input.GetAxis("Horizontal");
- rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
- if(facingRight == false && moveInput > 0)
- {
- flip();
- } else if (facingRight == true && moveInput < 0) {
- flip();
- }
- }
- void flip() {
- facingRight = !facingRight;
- Vector3 Scaler = transform.localScale;
- Scaler.x *= -1;
- transform.localScale = Scaler;
- }
- // Update is called once per frame
- void Update () {
- Animator.SetFloat("speed", Mathf.Abs(moveInput));
- if (isGrounded == true)
- {
- extraJump = extraJumpsValue;
- Animator.SetBool("isJumping", false);
- } else
- {
- Animator.SetBool("isJumping", true);
- }
- if(Input.GetKeyDown(KeyCode.UpArrow) && extraJump > 0 && cooldown == true)
- {
- rb.velocity = Vector2.up * jumpForce;
- extraJump--;
- } else if (Input.GetKeyDown(KeyCode.UpArrow) && extraJump == 0 && isGrounded == true) {
- rb.velocity = Vector2.up * jumpForce;
- }
- if(Input.GetKeyDown(KeyCode.Space) && isGrounded == true && cooldown == true)
- {
- speed = 0;
- Animator.SetBool("Transforming", true);
- cooldown = false;
- }
- if (TWasp == true && cooldown == true)
- {
- speed = 80;
- extraJumpsValue = 1;
- Animator.SetBool("TState", true);
- } else if(TWasp == false && cooldown == true)
- {
- speed = 50;
- extraJumpsValue = 0;
- Animator.SetBool("TState", false);
- }
- if (cooldown == false)
- {
- counter += Time.deltaTime;
- if(counter > 0.6)
- {
- cooldown = true;
- Animator.SetBool("Transforming", false);
- TWasp = !TWasp;
- counter = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement