So I’m working on a 2d platformer where the player is a circle, and instead of adding a groundcheck I wanted to make it so that you can jump whenever, but with a cooldown. I added an IEnumerator for the Coroutine JumpReset, but it keeps giving me an error code saying that “The type or namespace name ‘IEnumerator’ could not be found” and I’m truly confused, as I was looking at a different script I had using the same IEnumerator format, one that did work, when I was scripting the code that gives me the error.
Here’s the script that won’t work:
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed = 10f;
private bool isJumping = false;
private Rigidbody2D _rigidbody;
private void Start()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
private void Update()
{
var movement = Input.GetAxis("Horizontal");
var dash = Input.GetAxis("Horizontal");
_rigidbody.AddForce(new Vector2(movement, 0));
if (Input.GetButtonDown("Fire3"))
{
if (isJumping == false)
{
StartCoroutine(JumpReset());
}
}
}
IEnumerator JumpReset()
{
isJumping = true;
_rigidbody.AddForce(new Vector2(dash * 30, 12), ForceMode2D.Impulse);
yield return new WaitForSeconds(0.5f);
isJumping = false;
}
}
Thanks for your time, and have a good day or night.