using UnityEngine; using System.Collections; public class InputTest : MonoBehaviour { public System.Action Drag; void OnEnable() { Drag = DrayObject; } Vector3 scrPos; Vector3 temp; public virtual void DragObject() { scrPos = Camera.main.WorldToScreenPoint(transform.position);//将cube的坐标转换为屏幕坐标 temp = new Vector3(Input.mousePosition.x, Input.mousePosition.y, scrPos.z);// transform.position = Camera.main.ScreenToWorldPoint(temp);//将屏幕坐标转换为世界坐标 } void OnMouseDrag () { if (Drag != null)
{ Drag(); } } //void OnMouseDrag() //{ // transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(transform.position).z)); //} }