NGUI物件跟隨滑鼠拖拽移動
阿新 • • 發佈:2019-02-12
public Camera WNGUICamera; Vector3 _WoldPosition;//指標的初始位置 // Vector3 _WoldAng; Vector3 WscreenSpace; Vector3 Woffset; Vector3 WcurScreenSpace; Vector3 WcurPosition; //工具跟隨滑鼠拖拽移動 IEnumerator fnOnMouseDown() { WscreenSpace = WNGUICamera.WorldToScreenPoint(transform.position); Woffset = transform.position - WNGUICamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, WscreenSpace.z)); while (Input.GetMouseButton(0)) { //DrawLineScript.isMoveLine = true; if (Input.mousePosition.x > 0 && Input.mousePosition.x < Screen.width && Input.mousePosition.y > 0 && Input.mousePosition.y < Screen.height) { WcurScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, WscreenSpace.z); WcurPosition = WNGUICamera.ScreenToWorldPoint(WcurScreenSpace) + Woffset; transform.position = new Vector3(WcurPosition.x, WcurPosition.y, 0f); } yield return new WaitForFixedUpdate(); } }