unity ugui怎么做一个长安可以跟随移动的
1个回答
展开全部
<pre t="code" l="csharp">using UnityEngine;
using System.Collections;
using UnityEngine.EverySystem;
public class NewBehaviourScript : MonoBehaviour
{
public Canvas canvas;
public RectTransform rectTransform;
void Start()
{
rectTransform=transform as RectTransform; //也可以写成this.GetComponent lt;RectTransform;(),但是不建议;
canvas=GameObjcet.Find(;Canvas;).GetComponentlt;Canvas;();
}
void Update()
{
Vector2 pos;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transf
orm as RectTransform, Input.mousePosition, canvas.worldCamera, out pos))
{
rectTransform.anchoredPosition = pos;
Debug.Log(pos);
}
}
}
using System.Collections;
using UnityEngine.EverySystem;
public class NewBehaviourScript : MonoBehaviour
{
public Canvas canvas;
public RectTransform rectTransform;
void Start()
{
rectTransform=transform as RectTransform; //也可以写成this.GetComponent lt;RectTransform;(),但是不建议;
canvas=GameObjcet.Find(;Canvas;).GetComponentlt;Canvas;();
}
void Update()
{
Vector2 pos;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transf
orm as RectTransform, Input.mousePosition, canvas.worldCamera, out pos))
{
rectTransform.anchoredPosition = pos;
Debug.Log(pos);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询