En Unity, puedes detectar la tecla Shift izquierdo (LeftShift
) utilizando Input.GetKey()
o Input.GetKeyDown()
dentro del método Update()
.
void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
Debug.Log("Left Shift is being held down");
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
Debug.Log("Left Shift was just pressed");
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
Debug.Log("Left Shift was released");
}
}
Input.GetKey(KeyCode.LeftShift)
: Detecta si la tecla está siendo presionada en este frame.
Input.GetKeyDown(KeyCode.LeftShift)
: Detecta cuando la tecla fue presionada en este frame (solo una vez).
Input.GetKeyUp(KeyCode.LeftShift)
: Detecta cuando la tecla fue soltada en este frame.
Si estás usando el nuevo sistema de entrada (UnityEngine.InputSystem
), puedes hacerlo así:
using UnityEngine;
using UnityEngine.InputSystem;
void Update()
{
if (Keyboard.current.leftShiftKey.isPressed)
{
Debug.Log("Left Shift is being held down (New Input System)");
}
}
Jorge García
Fullstack developer