Page 1 of 1

Was ist das Äquivalent von GetKey im neuen Unity-Eingabesystem?

Posted: 14 Jan 2025, 09:15
by Guest
Es gibt die Ereignishandler „Gestartet“, „Durchgeführt“ und „Abgebrochen“, aber was ist, wenn ich erkennen möchte, ob ich die Taste auf einem Gamepad gedrückt halte? Wie schreibe ich das also grundsätzlich auf ein Gamepad mit dem neuen Eingabesystem um?

Code: Select all

private void Jump()
{
if (isTouchingGround == true && Input.GetKeyDown(KeyCode.Space))
{
isJumping = true;
jumpTimeCounter = jumpTime;
myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, 1 * jumpSpeed);
}

if (Input.GetKey(KeyCode.Space) && isJumping == true)
{
if (jumpTimeCounter > 0)
{
myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, 1 * jumpSpeed);
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
}
if (Input.GetKeyUp(KeyCode.Space))
{
isJumping = false;
}
}