//脚本挂在需要跟随鼠标移动的UI上 using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.EventSystems; public class CharacterControl : MonoBehaviour { public Camera UICamera; Vector3 scenePos; void Start () { EventTriggerListener.Get(gameObject).onDrag = OnMouseDrag; } void OnMouseDrag(GameObject img) { Vector2 mous = Input.mousePosition; scenePos = new Vector3(mous.x, mous.y, UICamera.WorldToScreenPoint(transform.position).z); transform.position = UICamera.ScreenToWorldPoint(scenePos); } }