Hello forum,
I’m pretty new to Unity’s updated Input System and I think it’s a great improvement so far, but I’m having incredible difficulty figuring this one out. The input bindings for the quicktime event button prompt are set in the inspector. They’re also being read correctly when performed. Does anyone know how to detect whether a button is pressed that is not mentioned in it’s InputAction action property?
Thanks in advance!
I have resolved the issue and edited my code for everyone to see.
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.InputSystem.Utilities;
public class QuicktimeButtonPrompt : MonoBehaviour
{
[Space(5), Header("Key Bindings"),Space(5)]
[Space(5),SerializeField] private InputAction action;
public void Init()
{
action.Enable();
action.performed += CorrectButtonPress;
//THE CODE SNIPPED BELOW HERE IS WHAT I WANTED.
InputSystem.onAnyButtonPress
.Where(e => !action.controls.Contains(e))
.CallOnce(inputControl => ReadInput(inputControl));
}
private void ReadInput(InputControl inputControl)
{
Debug.Log($"<color=red>{inputControl.name} doesn't match with the prompt! >:d</color>");
Finalize(false);
}
private void CorrectButtonPress(InputAction.CallbackContext callback)
{
if (quickTimeCountDown.CurrentPromptGameObject != gameObject) return;
Debug.Log($"<color=green>Successfully executed {gameObject.name}! :smile:</color>");
Finalize(true);
}
private void Finalize(bool wasSuccessful)
{
OnResult?.Invoke(wasSuccessful, this);
performedCorrectly = wasSuccessful;
RemoveInput();
}
private void RemoveInput() => action.Disable();
}