//脚本挂在需要跟随鼠标移动的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);
}
}
U3D-UI跟随鼠标中心移动
最新推荐文章于 2024-05-21 15:39:46 发布