using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UiFollowObj : MonoBehaviour {
Transform m_trans;
public Transform m_followTrans;
public GameObject m_child;
// Use this for initialization
void Start () {
m_trans = this.transform;
}
private void LateUpdate()
{
if (m_followTrans != null)
{
Vector2 player2DPosition = Camera.main.WorldToScreenPoint(m_followTrans.position);
m_trans.position = player2DPosition;
}
}
}


本文介绍了一个Unity脚本,用于使UI元素跟随特定的游戏对象移动。通过使用Camera.main.WorldToScreenPoint方法,确保UI位置始终相对于被跟踪对象,即使在摄像机移动时也能保持正确的位置。
1055

被折叠的 条评论
为什么被折叠?



