using UnityEngine; using System.Collections; public class mouse : MonoBehaviour { //private Vector3 lasePos; private Vector3 offSet; private Vector3 ScreenSpace; //1. void OnMouseDown() { ScreenSpace = Camera.main.WorldToScreenPoint(transform.position); offSet = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, ScreenSpace.z)); //lasePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, ScreenSpace.z)); print("down"); } //2. void OnMouseUp() { print("up"); } //3. void OnMouseDrag() { Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, ScreenSpace.z); Vector3 CurPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offSet; transform.position = CurPosition; //Vector3 curPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, ScreenSpace.z)); //Vector3 gapPos = curPos - lasePos; //transform.position = transform.position + gapPos; //lasePos = curPos; print("drag"); } //4.当鼠标移动到内部时 void OnMouseEnter() { print("enter"); } //5.当鼠标离开内部时 void OnMouseExit() { print("exit"); } //6.当鼠标持续停留在内部时 void OnMouseOver() { print("over"); } //7.鼠标停留在内部释放时调用 void OnMouseUpAsButton() { print("upAsButton"); } }
时间: 2024-09-30 11:47:27