找回密码
 立即注册
楼主: 辣条

[GUI] Unity3D 比较简单的scrollbar血条制作

[复制链接]
发表于 2012-8-13 10:10 | 显示全部楼层 |阅读模式

[code=csharp]using UnityEngine;  
using System.Collections;  
   
public class BloodBarTest : MonoBehaviour {  
   
    public GUISkin theSkin;  
    public float bloodValue = 0.0f;  
    private float tmpValue;  
    private Rect rctBloodBar;  
    private Rect rctUpButton;  
    private Rect rctDownButton;  
    private bool onoff;  
   
    // Use this for initialization   
    void Start () {  
        rctBloodBar = new Rect (20,20,20,200);  
        rctUpButton = new Rect (50,20,40,20);  
        rctDownButton = new Rect (50,50,40,20);  
        tmpValue = bloodValue;  
    }  
   
    void OnGUI (){  
    print (bloodValue);
        GUI.skin = theSkin;  
        if (GUI.Button (rctUpButton,"+")){  
            tmpValue = -1.0f;  
        }  
        if (GUI.Button (rctDownButton,"-")){  
      if(bloodValue<-0.0f&&bloodValue>-1.0f)
      {
         tmpValue += 0.1f;  
      }
        }  
        if (bloodValue > 0.0f) tmpValue = 0.0f;  
        if (bloodValue < -1.0f) tmpValue = -1.0f;  
   
      bloodValue = Mathf.Lerp(bloodValue,tmpValue,0.05f);
      
   
       // bloodValue = Mathf.Lerp(bloodValue,tmpValue,0.05f);  
        //~ Debug.Log (bloodValue + " " + tmpValue);   
        GUI.VerticalScrollbar(rctBloodBar, 1.0f, bloodValue,0.0f, 1.0f,GUI.skin.GetStyle("verticalScrollbar"));  
    }  
   
    // Update is called once per frame   
    void Update () {  
   
    }  
}  
[/code]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2012-10-13 12:51 | 显示全部楼层
大哥 你的动态图 怎么做的{:5_412:}
发表于 2012-11-8 15:56 | 显示全部楼层
这个实用,先收下了
发表于 2012-11-8 15:57 | 显示全部楼层
不过用GUI组件来做血条,有点不科学啊
发表于 2012-11-26 11:30 | 显示全部楼层
吓..这个. . 还可以噢.
发表于 2012-11-27 13:55 | 显示全部楼层
怎么能不科学能,gui组建一支在游戏的最前面的一层,而且还不需要很高的美术基础,相当使用的小细节啊
发表于 2012-11-29 20:00 | 显示全部楼层
谢谢楼主的代码哦对我有很大的帮助哦
发表于 2013-8-9 10:22 | 显示全部楼层
不錯的簡單應用~謝謝分享{:soso_e100:}
发表于 2017-2-19 10:03 | 显示全部楼层
好帖就是要顶
发表于 2017-2-19 10:38 | 显示全部楼层
难得一见的好帖
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-2 15:34 , Processed in 0.110919 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表