45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
namespace Game
|
|
{
|
|
public class CameraScroller : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
{
|
|
public bool isDragging { get; private set; }
|
|
|
|
float _yMax = 4.5f;
|
|
float _yMin = -1f;
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
isDragging = true;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
var main_cam = Camera.main;
|
|
|
|
if (main_cam != null)
|
|
{
|
|
var pos = main_cam.transform.position;
|
|
var new_y = pos.y;
|
|
new_y -= eventData.delta.y * 0.01f;
|
|
pos.y = Mathf.Clamp(new_y, _yMin, _yMax);
|
|
|
|
main_cam.transform.position = pos;
|
|
}
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
isDragging = false;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|