Unity Version: 2020.3.20f1
New Input System: Version 1.0.2 - January 21, 2021
I can print the current phase from the new input system in relation to touch.
Debug.Log("Current Phase: " + Touch.activeFingers[0].currentTouch.phase);
The code above prints “Began” which is correct.
However, if statements (booleans) always return false;
print(Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began));
Why is that?
Here is the full code:-
using UnityEngine;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
public class InputManager : MonoBehaviour
{
private void Awake()
{
}
private void OnEnable()
{
EnhancedTouchSupport.Enable();
Touch.onFingerDown += Touch_onFingerDown;
Touch.onFingerUp += Touch_onFingerUp;
Touch.onFingerMove += Touch_onFingerMove;
}
private void OnDisable()
{
EnhancedTouchSupport.Disable();
Touch.onFingerDown -= Touch_onFingerDown;
Touch.onFingerUp -= Touch_onFingerUp;
Touch.onFingerMove -= Touch_onFingerMove;
}
private void Touch_onFingerDown(Finger finger)
{
// Works fine
print(Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began));
// does not work
Debug.Log("Current Phase: " + Touch.activeFingers[0].currentTouch.phase);
///if (Touch.activeFingers.Count > 0)
if (Input.touchCount > 0 )
{
if (Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began))
{
print("This is never reached");
}
}
}