I am trying to make a basic controller engine. I made a bool variable called JumpWait to wait to be able to jump until touching ground. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TwoDController : MonoBehaviour
{
public float speed;
public int Jumps;
public bool InAir = false;
void OnCollisionEnter2D(Collision2D otherObj)
{
if (otherObj.gameObject.CompareTag("Ground"))
{
Jumps = 0;
}
}
private void Update()
{
if (Jumps == 0)
{
InAir = false;
}
if (Input.GetKey("a"))
{
transform.Translate(Vector3.left * speed * Time.deltaTime);
}
if (Input.GetKey("d"))
{
transform.Translate(Vector3.right * speed * Time.deltaTime);
}
if (Input.GetKey("w"))
Jumps += 1;
{
if (Jumps >= 1)
{
StartCoroutine("JumpWait");
transform.Translate(Vector3.up * speed * Time.deltaTime);
}
}
}
IEnumerator JumpWait()
{
yield return (new WaitUntil(InAir = false));
}
}
Could someone PLEASE help me out? i have been trying this for hours