ソースコード
using UnityEngine; public static class KeyCodeExt { public static bool IsPressing( this KeyCode self ) { return Input.GetKey( self ); } public static bool IsPressed( this KeyCode self ) { return Input.GetKeyDown( self ); } }
適用前
if ( Input.GetKey( KeyCode.Z ) ) { Debug.Log( "Pressing Z" ); } if ( Input.GetKeyDown( KeyCode.X ) ) { Debug.Log( "Pressed X" ); }
適用後
if ( KeyCode.Z.IsPressing() ) { Debug.Log( "Pressing Z" ); } if ( KeyCode.X.IsPressed() ) { Debug.Log( "Pressed X" ); }