Unity3D 人形血条制作小知识
这几天用Unity3D做个射击小游戏,想做个人形的血条。百思不得其解,后来问了网上的牛牛们,攻克了,事实上挺简单的,GUI里面有个函数DrawTextureWithTexCoords就能够实现图片的裁剪。非常方便。裁剪之后。相信大家就都会操作了。话不多说。贴上代码与截图效果。
using UnityEngine;
using System.Collections;
using UnityEditor;
public class drawTexture : MonoBehaviour {
public Texture back;//背景图
public Texture fore;//前景图
private float scale_height = 0.99f;
private float position_left=500f;
private float position_top=300f;
// Use this for initialization
void Start () {
}
void OnGUI()
{
GUI.DrawTexture (new Rect (position_left, position_top, back.width, back.height), back);
//GUI.DrawTexture (new Rect (500, 300, fore.width, fore.height), fore);
if (Input.GetKeyUp(KeyCode.Space)) {
scale_height=scale_height- 0.01f;
if(scale_height<0)
scale_height=0;
}
GUI.Label (new Rect(0,0,100,100),"scale_height"+scale_height);
GUI.DrawTextureWithTexCoords (new Rect (position_left, position_top+back.height*(1-scale_height), fore.width, fore.height*scale_height), fore,
new Rect(0,0,1, scale_height),true);
}
// Update is called once per frame
void Update () {
}
}
效果图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhbzY5/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
效果还不错吧。哈哈。
最新文章
- visual studio自动导入 using 的快捷键
- mysql 关系表 分组读取的方法
- TFS源代码管理的8大注意事项
- [EventBus源码解析] EventBus.register 方法详述
- IOS7新特性 edgesForExtendedLayout
- redis多实例运行
- Struts2接收参数的几种方式
- 流风ASP.NET框架商业版-工作流1.0简介
- Input输入字体颜色改变js(兼容IE)
- a 标签的四个伪类
- 设计模式- 主动对象(Active Object)
- Android获得Manifest在&;lt;meta-data&;gt;元件的值
- java 缓存ehcache的使用(使用方式一)
- Python3基础 使用 in notin 查询一个字符是否指定字典的键或者值
- 【拓扑排序】【线段树】Gym - 101102K - Topological Sort
- easyui treegrid实现显示checkbox并能获取到选定值的
- JS页面打开方式丶对话框及页面跳转方式
- Handsontable的前端分页与数据库分页
- 20 ViewPager Demo3指示器
- Linux下Power Management开发总结