这几天用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="">





效果还不错吧。哈哈。

最新文章

  1. visual studio自动导入 using 的快捷键
  2. mysql 关系表 分组读取的方法
  3. TFS源代码管理的8大注意事项
  4. [EventBus源码解析] EventBus.register 方法详述
  5. IOS7新特性 edgesForExtendedLayout
  6. redis多实例运行
  7. Struts2接收参数的几种方式
  8. 流风ASP.NET框架商业版-工作流1.0简介
  9. Input输入字体颜色改变js(兼容IE)
  10. a 标签的四个伪类
  11. 设计模式- 主动对象(Active Object)
  12. Android获得Manifest在&amp;lt;meta-data&amp;gt;元件的值
  13. java 缓存ehcache的使用(使用方式一)
  14. Python3基础 使用 in notin 查询一个字符是否指定字典的键或者值
  15. 【拓扑排序】【线段树】Gym - 101102K - Topological Sort
  16. easyui treegrid实现显示checkbox并能获取到选定值的
  17. JS页面打开方式丶对话框及页面跳转方式
  18. Handsontable的前端分页与数据库分页
  19. 20 ViewPager Demo3指示器
  20. Linux下Power Management开发总结

热门文章

  1. Linux - 硬件杂讲
  2. Web进行压力测试的小工具
  3. Ubuntu搭建docker环境
  4. BZOJ 4491 分块OR差分+线段树
  5. Npgsql使用入门(三)【批量导入数据】
  6. mvc 伪静态任意扩展名的实现方法
  7. mysql连接出现error node【1045】
  8. Vue组件的三种调用方式
  9. 纯CSS3文字Loading动画特效
  10. MySQL 5.6 Reference Manual-14.6 InnoDB Table Management