Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class saaa : MonoBehaviour
- {
- public float wallJumpPower = 10f;
- private bool hasWallJumped = false;
- private bool isTouchingWall = false;
- public float speed;
- public float jump;
- private Animator animator;
- private SpriteRenderer spriteRenderer;
- private float move;
- private int lastDirection = 1;
- public Rigidbody2D rb;
- public bool isJumping;
- private bool canDash = true;
- private bool isDashing;
- private float dashingpower = 16f;
- private float dashingTime = 0.2f;
- private float dashingCooldown = 1f;
- [SerializeField] private TrailRenderer tr;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- animator = GetComponent<Animator>();
- spriteRenderer = GetComponent<SpriteRenderer>();
- if (tr != null)
- {
- tr.emitting = false;
- }
- }
- void Update()
- {
- if (isDashing)
- {
- return;
- }
- // Hareket giri�i
- if (Input.GetKey(KeyCode.D))
- {
- move = 1f;
- lastDirection = 1;
- }
- else if (Input.GetKey(KeyCode.A))
- {
- move = -1f;
- lastDirection = -1;
- }
- else
- move = 0f;
- rb.linearVelocity = new Vector2(speed * move, rb.linearVelocity.y);
- animator.SetBool("isWalking", move != 0);
- if (move > 0f)
- spriteRenderer.flipX = false;
- else if (move < 0)
- spriteRenderer.flipX = true;
- if (Input.GetButtonDown("Jump"))
- {
- if (!isJumping)
- {
- animator.SetBool("zıp?", true);
- rb.AddForce(new Vector2(rb.linearVelocity.x, jump));
- isJumping = true;
- }
- else if (isTouchingWall && !hasWallJumped)
- {
- animator.SetBool("zıp?", true);
- rb.AddForce(new Vector2(rb.linearVelocity.x * 0.5f, wallJumpPower), ForceMode2D.Impulse);
- hasWallJumped = true;
- }
- }
- if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
- {
- animator.SetBool("dash?", true);
- StartCoroutine(Dash());
- }
- }
- private void OnCollisionEnter2D(Collision2D collison)
- {
- if (collison.gameObject.CompareTag("Floor"))
- {
- isJumping = false;
- animator.SetBool("zıp?", false);
- }
- else if (collison.gameObject.CompareTag("Diken"))
- {
- isTouchingWall = true;
- hasWallJumped = false;
- }
- }
- private void OnCollisionExit2D(Collision2D collision)
- {
- if (collision.gameObject.CompareTag("Floor"))
- {
- isJumping = true;
- animator.SetBool("zıp?", true);
- }
- else if (collision.gameObject.CompareTag("Diken"))
- {
- isTouchingWall = false;
- }
- }
- private IEnumerator Dash()
- {
- canDash = false;
- isDashing = true;
- float originalGravity = rb.gravityScale;
- rb.gravityScale = 0f;
- rb.linearVelocity = new Vector2(lastDirection * dashingpower, 0f);
- tr.emitting = true;
- yield return new WaitForSeconds(dashingTime);
- tr.emitting = false;
- rb.gravityScale = originalGravity;
- isDashing = false;
- yield return new WaitForSeconds(dashingCooldown);
- canDash = true;
- animator.SetBool("dash?", false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment