You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
using System.Runtime.InteropServices; |
|
using UnityEngine; |
|
|
|
public class MiddleButtonDrag : MonoBehaviour |
|
{ |
|
|
|
public GameObject Target; |
|
|
|
private Vector3 prevPos = Vector3.zero; |
|
|
|
private Vector3 FirstOutPosition = Vector3.zero; |
|
|
|
|
|
void LateUpdate() |
|
{ |
|
if (Input.GetMouseButtonDown(2)) |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(Target.transform.position); |
|
prevPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
FirstOutPosition = prevPos; |
|
|
|
} |
|
|
|
if (Input.GetMouseButtonUp(2)) |
|
{ |
|
//prevPos = Vector3.zero; |
|
//Cursor.visible = true; |
|
} |
|
|
|
if (Input.GetMouseButton(2)) |
|
{ |
|
var screenSpace = Camera.main.WorldToScreenPoint(Target.transform.position); |
|
|
|
var currPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z); |
|
|
|
var prev = Camera.main.ScreenToWorldPoint(prevPos); |
|
var curr = Camera.main.ScreenToWorldPoint(currPos); |
|
|
|
var offset = curr - prev; |
|
|
|
offset.y = 0; |
|
Target.transform.position += -offset; |
|
|
|
prevPos = currPos; |
|
|
|
//Cursor.visible = false; |
|
|
|
|
|
|
|
//if (currPos.x < 0 || currPos.x > Screen.width) |
|
//{ |
|
// Cursor.lockState = CursorLockMode.Locked; |
|
// Cursor.lockState = CursorLockMode.None; |
|
|
|
// var screenSpace_ = Camera.main.WorldToScreenPoint(Target.transform.position); |
|
// prevPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace_.z); |
|
//} |
|
//else if (currPos.y < 0 || currPos.y > Screen.height) |
|
//{ |
|
// Cursor.lockState = CursorLockMode.Locked; |
|
// Cursor.lockState = CursorLockMode.None; |
|
|
|
// var screenSpace_ = Camera.main.WorldToScreenPoint(Target.transform.position); |
|
// prevPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace_.z); |
|
//} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
} |