I'd like to know how to make a circular progressbar or timer-type effect. Basically, given a value [0..1], it will "fill in" a portion of a circle on the GUI that circularly represents the value. So if I give it 0.33, it should fill in 1/3 of the circle, and so on. These types of GUI elements are useful for timers and that sort of thing.
I really can't think of a way to do this off the top of my head, so if anyone can either post some code or point me in the right direction, that would be awesome. :)
The easiest way is to use an alpha gradient texture:
Which is used as a mask in an alpha test (transparent cutout) shader. You change the _Cutoff property to indicate which percentage should be used, ranging from 0..1. This code would make the bar empty when the mouse pointer is on the right side of the screen, going up to full as you move the mouse pointer to the left side (see demo):
function Update () {
renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, Screen.width, Input.mousePosition.x));
}
In the demo, there are three textures; one for the regular graphics (using normal alpha for nice anti-aliasing), one for the green health bar (using alpha cutoff), and a solid red behind the first two that shows through where there's no green. The non-alpha part of the health bar texture is just a block of solid green, although it doesn't have to be...you can make it look like whatever you want of course.
FYI this can be done very easily with the new UI. All you need is a sprite with a circular texture (I’ve provided one). Add an Image object to your scene, and the provided sprite as the Source Image, and set the Image Type to Filled.
You can access the fill amount via scripting by getting a reference to the Image component (make sure to add import or add a using statement for UnityEngine.UI).
Unity has since added the Sprite Mask component which works very similarly to the alpha cutout shader @Eric5h5 posted. Unity - Manual: Sprite Masks
I fixed your code highlighting. However I would recommend you read the [site navigation guide][1] as suggested on the right side if you have trouble how to properly format your posts. The guide is a bit messy. Scroll down about a third to the section "Posting Questions, Answers and Comments". [1]: https://answers.unity.com/page/userguide.html
hers' my workaround . http://codeskool.blogspot.in/p/unity-hacks.html
– nikhil38In Unity 5 You need Image component with "Image type" parameter set to "Filled". Choose "Fill method" Radial 360. Last thing that you need to change parameter "Fill Amount" by script. for script you can refer http://www.unityrealm.com/how-to-make-a-circular-progress-bar-in-unity-ui/
– Noob_VulcanFor example, in your enemyChase script; ... void Update () { if (player != null && Vector3.Distance (destination, player.position) > 1.0f) { destination = player.position; target.destination = destination; } } ...
– Namey5