How do i make a health bar

I made a classic health bar with GUI that looks like this:
MyHealthBar

It’s just a classic GUI scroll bar or whatever…

But i want to make my health bar look like this example:
ExampleHealthBar

I really need this guys, i hope this is easy for you. Thanks !

Ok, you see the script has this one line :

	renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, Screen.width, Input.mousePosition.x));

Mathf.InverseLerp is giving Input.mousePosition.x as a percentage between 0 and Screen.width. This means if the screen is 800 wide, and mouseX is 160, then what is returned is 0.2 or 20% ( 0.2 * 800 = 160 ).

This is what you need to change to make it work with health. If the minimum and maximum is 0 and Screen.width, change it to 0 and maximumHealth variable. Then for Input.mousePosition.x, change this to your health variable.

so yours would look something like :

renderer.material.SetFloat( "_Cutoff", Mathf.InverseLerp(0, maxHealth, health) );

Here is the API for Mathf.InverseLerp : Unity - Scripting API: Mathf.InverseLerp