博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原】Unity3d 类似Dota血条
阅读量:7009 次
发布时间:2019-06-28

本文共 1016 字,大约阅读时间需要 3 分钟。

实现原理:动态改变GUItexture的宽度。

 

 

  

EnemyInfo enemyInfo;    public GUITexture enemyBoxGUI;    private Texture enemyBox;    private Texture enemyHp;    private int currentHp;    private float hpLength;    // Use this for initialization    void Start ()    {    enemyInfo=gameObject.transform.parent.GetComponent
(); enemyBox=enemyBoxGUI.texture; enemyHp=guiTexture.texture; currentHp=enemyInfo.Health(); hpLength=enemyHp.width/3; } // Update is called once per frame void Update () { print(currentHp); Vector3 pos=Camera.mainCamera.WorldToViewportPoint(transform.parent.position); enemyBoxGUI.transform.position=new Vector3(pos.x-0.05f,pos.y,pos.z-0.2f); guiTexture.transform.position=new Vector3(pos.x-0.05f,pos.y,pos.z-0.2f); enemyBoxGUI.pixelInset=new Rect(10,20,enemyBox.width/6,enemyBox.height/8); guiTexture.pixelInset=new Rect(10,25,hpLength*currentHp/enemyInfo.AllHealth,enemyHp.height/3); currentHp=enemyInfo.Health(); }

实现效果:

 

转载地址:http://gqvtl.baihongyu.com/

你可能感兴趣的文章
hdu 2144(LCS+并查集)
查看>>
JavaScript中逗号运算符
查看>>
盘点武汉十大宜居地段
查看>>
LeetCode题解:Rotate List
查看>>
进程关系之孤儿进程组
查看>>
Foundation框架—字符串
查看>>
数据库设计中的14个技巧
查看>>
7月份文章回顾
查看>>
25个顶级的jQuery表格插件
查看>>
memcached命令行操作详解,命令选项的详细解释
查看>>
Linux pipe函数
查看>>
java msgbox
查看>>
发布两款JQ小插件(图片查看器 + 分类选择器),开源
查看>>
linux中的namespace
查看>>
动态规划0—1背包问题
查看>>
Linux命令-权限管理命令:chgrp
查看>>
这张表的字符串 在另一张表中是否存在
查看>>
【Win10 应用开发】解决VS 2015 RC不能调试手机应用的问题
查看>>
如何学习开源项目
查看>>
读书笔记3 Socket
查看>>