Fix Object Instantiating
This commit is contained in:
35
Assets/Scripts/Services/InputService.cs
Normal file
35
Assets/Scripts/Services/InputService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Services.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Services {
|
||||
public class InputService : MonoBehaviour, IInputService
|
||||
{
|
||||
public event Action<Vector2> OnPointerDown;
|
||||
public event Action<Vector2> OnPointerUp;
|
||||
|
||||
private bool wasDown;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Mouse
|
||||
var isDown = Input.GetMouseButton(0);
|
||||
if (!wasDown && isDown)
|
||||
OnPointerDown?.Invoke(Input.mousePosition);
|
||||
|
||||
if (wasDown && !isDown)
|
||||
OnPointerUp?.Invoke(Input.mousePosition);
|
||||
|
||||
wasDown = isDown;
|
||||
|
||||
// Optional: Touch (if you want both, you can merge logic more carefully)
|
||||
if (Input.touchCount <= 0) return;
|
||||
|
||||
var t = Input.GetTouch(0);
|
||||
if (t.phase == TouchPhase.Began)
|
||||
OnPointerDown?.Invoke(t.position);
|
||||
else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
|
||||
OnPointerUp?.Invoke(t.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user