Unity is a mistake here?

using UnityEngine; public class PlayerMovement : MonoBehaviour {  public float moveSpeed = 5f;  public float jumpForce = 10f;  public Transform groundCheck;  public LayerMask groundLayer;  private bool canDash = true;  private bool isDashing;  public float dashingPower = 24f;  public float dashingTime = 0.2f;  public float dashingCooldown = 1f;  [SerializeField] private TrailRenderer tr;  private Rigidbody2D rb;  private bool isGrounded;  void Start()  {    rb = GetComponent<Rigidbody2D>();  }  void Update()  {        if(isDashing)    {      return;    }    float moveHorizontal = Input.GetAxis("Horizontal");        Vector2 movement = new Vector2(moveHorizontal, 0);    rb.velocity = new Vector2(movement.x * moveSpeed, rb.velocity.y);        if (moveHorizontal > 0)    {      transform.localScale = new Vector3(0.5f, 0.4835544f, 0.5f); // Blick nach rechts    }    else if (moveHorizontal < 0)    {      transform.localScale = new Vector3(-0.5f, 0.4835544f, 0.5f); // Blick nach links    }        isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, groundLayer);    if (isGrounded && Input.GetButtonDown("Jump"))    {      rb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);    }    if(Input.GetKeyDown(KeyCode.LeftShift) && canDash)    {     StartCoroutine(Dash());    }  }  private void FixedUpdate()  {    if(isDashing)    {      return;    }  }  private IEnumerator Dash()  {    canDash = false;    isDashing = true;    float originalGravity = rb.gravityScale;    rb.gravityScale = 0f;    rb.velocity = new Vector2(transform.localScale.x * 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;  } }
(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
DarkSolutions
5 months ago

You lack the use instructions in your script.

For the IEnumerator you can add the following:

using UnityEngine;
using System.Collections;