r/UnityHelp • u/mARTkon • Feb 05 '21
PROGRAMMING When I press space nothing happens. I think it's because the delay is not working. (If i remove the text in bold the player goes up as intented)
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class Jumping : MonoBehaviour
{
public float jumpHeight = 2;
public int airTime = 1000;
bool isAir = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
//jumping
transform.position = new Vector3(0, 1 + jumpHeight, 0);
isAir = true;
}
if(isAir != false)
{
Task.Delay(airTime);
transform.position = new Vector3(0, 1, 0);
}
}
}
3
Upvotes