UGUI 制作血条

来源:互联网 发布:华西交易软件下载 编辑:程序博客网 时间:2024/04/29 10:04

今天学习一下如何实现UGUI 2dUI跟随3d物体移动的效果
创建cube,创建Image。image作为血条,跟随cube移动
在cube上面添加脚本

using UnityEngine;using System.Collections;public class FlowTest : MonoBehaviour {    public RectTransform rectBloodPos;    public int offstex;    public int offsety;    // Update is called once per frame    void Update () {        //get ScreenPoint...Important        Vector2 vec2 = Camera.main.WorldToScreenPoint (this.gameObject.transform.position);        rectBloodPos.anchoredPosition = new Vector2 (vec2.x-Screen.width/2+0, vec2.y-Screen.height/2+60);//控制偏移量        //rectBloodPos.anchoredPosition = vec2 + new Vector2(offstex,offsety);    }}

运行效果:
这里写图片描述

0 0
原创粉丝点击