UI根据鼠标移动
< 返回列表时间: 2016-03-11来源:OSCHINA
using UnityEngine; using System.Collections; public class NewBehaviourScript : MonoBehaviour { Canvas canvas; RectTransform rectTransform; // Use this for initialization void Start () { rectTransform = transform as RectTransform; canvas = GameObject.Find("Canvas").GetComponent<Canvas>(); } // Update is called once per frame void Update () { Vector2 pos; if(RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out pos)){ rectTransform.anchoredPosition = pos; } } }

热门排行