28 lines
838 B
C#
28 lines
838 B
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
[RequireComponent(typeof(MeshCollider))]
|
||
|
public class SliderKnob : MonoBehaviour
|
||
|
{
|
||
|
public event Action<SliderKnob> OnDrag;
|
||
|
|
||
|
private Vector3 screenPoint;
|
||
|
private Vector3 offset;
|
||
|
|
||
|
void OnMouseDown()
|
||
|
{
|
||
|
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
|
||
|
|
||
|
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
|
||
|
}
|
||
|
|
||
|
void OnMouseDrag()
|
||
|
{
|
||
|
OnDrag?.Invoke(this);
|
||
|
/* Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
|
||
|
|
||
|
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
|
||
|
transform.position = curPosition; */
|
||
|
}
|
||
|
}
|