forked from mevulfmp3/hangtian
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.
42 lines
1.1 KiB
42 lines
1.1 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PinPreciseDrag : MonoBehaviour
|
|
{
|
|
|
|
Vector3 target_Screen;
|
|
Vector3 target_World;
|
|
Vector3 mouse_Screen;
|
|
Vector3 mouse_World;
|
|
Vector3 offset;
|
|
bool IsClickTarget;
|
|
|
|
private void Start()
|
|
{
|
|
IsClickTarget = false;
|
|
target_Screen = Camera.main.WorldToScreenPoint(transform.position);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButton(0) && IsClickTarget == true)
|
|
{
|
|
mouse_Screen = new Vector3(Input.mousePosition.x, Input.mousePosition.y, target_Screen.z);
|
|
mouse_World = Camera.main.ScreenToWorldPoint(mouse_Screen);
|
|
|
|
transform.position = mouse_World + offset;
|
|
}
|
|
}
|
|
|
|
void OnMouseDown()
|
|
{
|
|
IsClickTarget = true;
|
|
mouse_Screen = new Vector3(Input.mousePosition.x, Input.mousePosition.y, target_Screen.z);
|
|
mouse_World = Camera.main.ScreenToWorldPoint(mouse_Screen);
|
|
|
|
offset = transform.position - mouse_World; //朕炎麗悶弊順了崔 受肇 報炎弊順了崔
|
|
}
|
|
|
|
}
|