luoyikun

导航

unity3d:ui跟着gameobject移动

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;
        }
    }

}

在这里插入图片描述

posted on 2018-09-22 14:50  luoyikun  阅读(13)  评论(0)    收藏  举报  来源