Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 684 Bytes

File metadata and controls

37 lines (28 loc) · 684 Bytes

UNT0025 Input.GetKey overloads with KeyCode argument

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.