Touch Position#
Input / Touch Position
Can Read
Cannot Write
Description#
Returns current position of the specified finger touching the screen
Parameters#
| Name | Description |
|---|---|
| Finger | The zero based index of the touch. Returns nothing when out of range |
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Touch Position")]
[Category("Input/Touch Position")]
[Description("Returns current position of the specified finger touching the screen")]
[Image(typeof(IconTouch), ColorTheme.Type.Blue, typeof(BadgePosition))]
[Parameter("Finger", "The zero based index of the touch. Returns nothing when out of range")]
[Keywords("Screen", "Mobile", "Tap", "Point", "Finger")]
[Serializable]
public class TypeVector2InputTouchPosition : TypeVector2
{
[SerializeField] private GetInteger m_Finger = new GetInteger(0);
public override Vector2 Get(Args args)
{
Touchscreen touchscreen = Touchscreen.current;
if (touchscreen == null) return default;
int finger = this.m_Finger.GetInt(args);
if (finger < 0 || finger >= touchscreen.touches.Count) return default;
return touchscreen.touches[finger].position.ReadValue();
}
public override string ToString()
{
return $"Touch {this.m_Finger} Position";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}