using UnityEngine;
public class Swipe : MonoBehaviour
{
InputMaster input;
Vector2 startPos;
void Awake()
{
input = new InputMaster();
input.Enable();
}
void Start()
{
input.Touch.Tap.performed += ctx => CachePosition();
}
void CachePosition()
{
startPos = input.Touch.Position.ReadValue<Vector2>();
print(startPos) // !prints "(0,0)" on first call and then prints appropriate values.
}
}
What I’m trying to accomplish here is to cache screen position of tap on tap (event). And it works fine from the second call onwards. But on the first call it returns Vector.zero (0,0). I don’t get what the problem might be caused by, I’ll try to leave any releavant information here.
These 2 input actions has no interactions or processors.
“Tap” action is button bind to “Primary Touch/Tap [Touchscreen]”.
“Position” action is of type “value” - “Vector2” and pretty self explainatory bind to “Position [Touchscreen]”.
Ok, Let me tell the possibilies then.
First => make sure your Tap action is Button and interactions is selected press and release.
and for Bindings for Tap action will be PrimaryTouch/TouchContact? and Left Mouse Button.
Second make sure your Position action is Pass through and Type is Vector2.
and For bindings will be again Primary Touch/Position and Mouse Position.
UPD: I forked their repo on github (v 1.1.0), made some fixes and improvements. So now this seems to be fixed, at least for me. Check this out at: GitHub
–
now it works right (without subscription inside the “PrimaryTouchPosition.started” event)
@yanerobot My solution for this is to make the programme wait until the end of the first frame before calling the function again. Link to the code answer below: