These days with Unity3d do a shooting games, want to make a human blood bar, think not its solution, then asked the online cattle and cows, solved, actually quite simple, GUI inside has a function drawtexturewithtexcoords can realize the cutting of the picture, Very convenient, after cutting, I believe everyone will operate, words do not say, paste the code and effect.
Using unityengine;
Using System.Collections;
using unityeditor;
Public class Drawtexture:monobehaviour {
public Texture back;//background map
public Texture fore;//foreground map
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 (+, Fore.width, fore.height), fore);
if ( input.getkeyup ( Keycode.space)) {
9> scale_height=scale_height-0.01f;
if (scale_height<0)
< c22> scale_height=0;
}
GUI . Label (New Rect (0,0,100,100), "Scale_height" +scale_height);
&NBSP; GUI. Drawtexturewithtexcoords (new Rect (Position_left, position_top+back.height* (1-scale_height) , Fore.width, fore.height*scale_height), Fore,
< c32> new Rect (0,0,1, Scale_height), true);
}
/ /Update is called once per frame
void Update () {
}
}
:
The effect is good, haha.
Unity3d human blood strips making trivia