mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
28 lines
680 B
C#
28 lines
680 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Spine.Unity.Examples {
|
|
public class DraggableTransform : MonoBehaviour {
|
|
|
|
Vector2 mousePreviousWorld, mouseDeltaWorld;
|
|
Camera mainCamera;
|
|
|
|
void Start () {
|
|
mainCamera = Camera.main;
|
|
}
|
|
|
|
void Update () {
|
|
Vector2 mouseCurrent = Input.mousePosition;
|
|
Vector2 mouseCurrentWorld = mainCamera.ScreenToWorldPoint(new Vector3(mouseCurrent.x, mouseCurrent.y, -mainCamera.transform.position.z));
|
|
|
|
mouseDeltaWorld = mouseCurrentWorld - mousePreviousWorld;
|
|
mousePreviousWorld = mouseCurrentWorld;
|
|
}
|
|
|
|
void OnMouseDrag () {
|
|
transform.Translate(mouseDeltaWorld);
|
|
}
|
|
}
|
|
}
|