zoukankan      html  css  js  c++  java
  • 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 () {

             

        }

    }


    效果图:




    效果还不错吧。哈哈。

  • 相关阅读:
    导出大智慧L2要密码的公式
    SQL Server 索引结构及其使用
    职业式证券交易全貌向职业交易员进军者鉴[转]
    sqlite多字段拼接方法
    推荐两个UI、PSD文件搜索网站
    利用事件冒泡和阻止事件冒泡的例子
    js通过八个点 拖动改变div大小
    匿名函数运用js脚本一对圆括号
    js对象转换为json格式的jquery辅助类
    简单清晰的缓冲运动框架
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5204706.html
Copyright © 2011-2022 走看看