Guest User

Untitled

a guest
Jul 20th, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4. public class saaa : MonoBehaviour
  5. {
  6. public float wallJumpPower = 10f;
  7. private bool hasWallJumped = false;
  8. private bool isTouchingWall = false;
  9. public float speed;
  10. public float jump;
  11. private Animator animator;
  12. private SpriteRenderer spriteRenderer;
  13. private float move;
  14. private int lastDirection = 1;
  15. public Rigidbody2D rb;
  16. public bool isJumping;
  17. private bool canDash = true;
  18. private bool isDashing;
  19. private float dashingpower = 16f;
  20. private float dashingTime = 0.2f;
  21. private float dashingCooldown = 1f;
  22. [SerializeField] private TrailRenderer tr;
  23.  
  24.  
  25. void Start()
  26. {
  27. rb = GetComponent<Rigidbody2D>();
  28. animator = GetComponent<Animator>();
  29. spriteRenderer = GetComponent<SpriteRenderer>();
  30.  
  31. if (tr != null)
  32. {
  33. tr.emitting = false;
  34. }
  35.  
  36. }
  37. void Update()
  38. {
  39. if (isDashing)
  40. {
  41. return;
  42. }
  43. // Hareket giri�i
  44. if (Input.GetKey(KeyCode.D))
  45. {
  46. move = 1f;
  47. lastDirection = 1;
  48. }
  49. else if (Input.GetKey(KeyCode.A))
  50. {
  51. move = -1f;
  52. lastDirection = -1;
  53. }
  54. else
  55. move = 0f;
  56.  
  57.  
  58. rb.linearVelocity = new Vector2(speed * move, rb.linearVelocity.y);
  59. animator.SetBool("isWalking", move != 0);
  60. if (move > 0f)
  61. spriteRenderer.flipX = false;
  62. else if (move < 0)
  63. spriteRenderer.flipX = true;
  64.  
  65. if (Input.GetButtonDown("Jump"))
  66. {
  67. if (!isJumping)
  68. {
  69. animator.SetBool("zıp?", true);
  70. rb.AddForce(new Vector2(rb.linearVelocity.x, jump));
  71. isJumping = true;
  72. }
  73. else if (isTouchingWall && !hasWallJumped)
  74. {
  75. animator.SetBool("zıp?", true);
  76. rb.AddForce(new Vector2(rb.linearVelocity.x * 0.5f, wallJumpPower), ForceMode2D.Impulse);
  77. hasWallJumped = true;
  78. }
  79. }
  80. if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
  81. {
  82. animator.SetBool("dash?", true);
  83. StartCoroutine(Dash());
  84. }
  85.  
  86. }
  87.  
  88. private void OnCollisionEnter2D(Collision2D collison)
  89. {
  90. if (collison.gameObject.CompareTag("Floor"))
  91. {
  92. isJumping = false;
  93. animator.SetBool("zıp?", false);
  94. }
  95. else if (collison.gameObject.CompareTag("Diken"))
  96. {
  97. isTouchingWall = true;
  98. hasWallJumped = false;
  99. }
  100. }
  101. private void OnCollisionExit2D(Collision2D collision)
  102. {
  103. if (collision.gameObject.CompareTag("Floor"))
  104. {
  105. isJumping = true;
  106. animator.SetBool("zıp?", true);
  107. }
  108. else if (collision.gameObject.CompareTag("Diken"))
  109. {
  110. isTouchingWall = false;
  111.  
  112.  
  113. }
  114.  
  115.  
  116. }
  117. private IEnumerator Dash()
  118. {
  119. canDash = false;
  120. isDashing = true;
  121. float originalGravity = rb.gravityScale;
  122. rb.gravityScale = 0f;
  123. rb.linearVelocity = new Vector2(lastDirection * dashingpower, 0f);
  124. tr.emitting = true;
  125. yield return new WaitForSeconds(dashingTime);
  126. tr.emitting = false;
  127. rb.gravityScale = originalGravity;
  128. isDashing = false;
  129. yield return new WaitForSeconds(dashingCooldown);
  130. canDash = true;
  131. animator.SetBool("dash?", false);
  132. }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment