feat: add FlickArea UI component for gesture capture
This commit is contained in:
31
Assets/Script/FlickArea.cs
Normal file
31
Assets/Script/FlickArea.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
public class FlickArea : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||||||
|
{
|
||||||
|
public BallShooter ballShooter;
|
||||||
|
|
||||||
|
private Vector2 startPos;
|
||||||
|
private float startTime;
|
||||||
|
|
||||||
|
public void OnPointerDown(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
startPos = eventData.position;
|
||||||
|
startTime = Time.time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPointerUp(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
Vector2 endPos = eventData.position;
|
||||||
|
float endTime = Time.time;
|
||||||
|
|
||||||
|
Vector2 swipeDelta = endPos - startPos;
|
||||||
|
float swipeTime = endTime - startTime;
|
||||||
|
|
||||||
|
// Ensure swipeTime is not 0 to avoid division by zero
|
||||||
|
if (swipeTime > 0 && ballShooter != null)
|
||||||
|
{
|
||||||
|
ballShooter.FlickShoot(swipeDelta, swipeTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user