Unity NGUI实现角色名追随角色移动

来源:互联网 发布:azul by moussy淘宝 编辑:程序博客网 时间:2024/04/29 11:17
using UnityEngine;public class FloatingText : MonoBehaviour{    private UILabel _lbl;    private Vector3 _pos;    public GameObject _target;    public Camera worldCamera;    public Camera guiCamera;    void Awake()    {        _t = transform;//当前对象        _lbl = GetComponent<UILabel>();//获取label        if (_lbl == null)        {            Debug.LogError("Could not find the UILabel for the floating text.");        }    }    public void LateUpdate()    {        //follow the gameobject around on the screen        worldCamera = NGUITools.FindCameraForLayer(_target.layer);//获取MainCamera        guiCamera = NGUITools.FindCameraForLayer(gameObject.layer);//获取UICamera        _pos = worldCamera.WorldToViewportPoint(_target.transform.position);        _pos = guiCamera.ViewportToWorldPoint(_pos);        _pos.z = 0f;        _t.position = _pos;//设置label的坐标    }                                                                                                                                                       }


0 0
原创粉丝点击