How to detect if the player is idle

Hello everyone,

I’m making a horror game and using the standard unity fps controller i want to detect if the player is AFK for 2 minutes so a sound can be played.

How do i go about doing this without changing code of the fps controller if possible?

Thanks!
Nikk

Here is a much cleaner way of doing this

int IdleTimeSetting = 60;
float LastIdleTime;

        void Awake() {

               LastIdleTime = Time.time;
        }
        
        private void Update() {
        
                if(Input.anyKey){
                    LastIdleTime = Time.time;
                }
            }
        
        public bool IdleCheck(){
                return Time.time - LastIdleTime > IdleTimeSetting;
        }

public int time = 0;

                 //Use fixed update beacuase its called every fixed framerate frame
                  void FixedUpdate () {
     
                     if(!Input.anyKey){
                         
                         //Starts counting when no button is being pressed
                         time = time + 1;
                     } else {
                         
                         // If a button is being pressed restart counter to Zero
                         time = 0;
                     }
                     
              //Now after 100 frames of nothing being pressed it will do activate this if statement
                     if(time == 100) {
                         Debug.Log("100 frames passed with no input");
                         
                         //Now you could set time too zero so this happens every 100 frames
                         time = 0;
                     }
     
                 }