usingUnityEngine;usingUnityEngine.InputSystem;publicclassActionTester:MonoBehaviour{publicPlayerInputm_PlayerInput;// hook this up to your player input componentpublicstringm_ActionNameToCheck="Fire";// set this to the name of the action you want to checkpublicboolActionIsPressed(){// you may need to check the cAction.type to ensure this works for other action typesfloatfCurrentValue=m_cAction.ReadValue<float>();return(fCurrentValue!=0f);}//////////////////////////////////////////////////////////////////////////// NOTE: this assumes the current actionmap is not going to changeInputActionm_cAction=null;voidStart(){m_cAction=m_PlayerInput.currentActionMap.FindAction(m_ActionNameToCheck);}voidUpdate(){if(ActionIsPressed()){Debug.Log("["+Time.time+"] "+m_ActionNameToCheck+"!");}}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.