您的位置:首页 > 移动开发 > Unity3D

unity 在UI中 点击画布 返回鼠标所在画布的位置

2017-11-19 17:25 330 查看
这个功能很实用 大家可以试试
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class aaa : MonoBehaviour {
Vector3 go ;
public GameObject bul;
public Canvas canvas;//将画布拖进来
// Use this for initialization
void Start () {

}
void Update () {

if (Input.GetMouseButton (0)) {

Vector2 _pos = Vector2.one;
RectTransformUtility.ScreenPointToLocalPointInRectangle (canvas.transform as RectTransform,
Input.mousePosition, canvas.worldCamera, out _pos);
Debug.Log ("pos:" + _pos);

}

}
}
将上面的这个脚本挂在摄像机上  然后拖画布 就可以了 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: