UNT0025 Input.GetKey overloads with KeyCode argument
May 25, 2021 ยท View on GitHub
Input.GetKey* methods have overloads taking a KeyCode argument instead of a magic string. Those are safer and more efficient.
Examples of patterns that are flagged by this analyzer
using UnityEngine;
class Camera : MonoBehaviour
{
public void Update()
{
if (Input.GetKey("q"))
return;
}
}
Solution
Use KeyCode argument instead:
using UnityEngine;
class Camera : MonoBehaviour
{
public void Update()
{
if (Input.GetKey(KeyCode.Q))
return;
}
}
A code fix is offered for this diagnostic to automatically apply this change.