- Home /
progress bar
i am trying to create a health bar using draw texture it is working fine for me but the by using draw texture the texture itself is moving from its original position and how to increase the health bar from bottom to upward direction(- y direction).I want my texture should gradually increase from its original position to the clamped value with out moving the texture from its original position.Is any other method is there for health bar other than draw texture or how to use draw texture properly to get the result i want.
http://answers.unity3d.com/questions/7846/how-do-i-make-a-progress-bar.html
i have tried the code used in above link for making a health bar it is working fine for me. The using above code the texture itself is moving from its original position i want the health bar should increase gradually from its original position. i want to increase health bar in (- y direction).in above code if i am fixing the texture position to var pos : Vector2 = new Vector2(20,40);
the whole texture starts move upwards.can you please fix this error in my coding as i am new to coding
I really don't understand... can you edit this question so it is understandable? dot-points maybe?
Answer by Peter G · Oct 05, 2011 at 12:24 AM
I don't think you want to use DrawTexture(). You would be better off having an alpha-cutoff plane in the center of your screen and then lerp the alpha cutoff parameter as the time passes so that the entire progress bar is visible.
var endTime : float = 10;
// time is just one possible way you could lerp. Player position is another. Or score
function Update () {
var lerpParameter : float = 1 - Mathf.InverseLerp(0 , endTime , Time.time);
//returns the lerp parameter between 2 values.
renderer.material.SetFloat( "_Cutoff" , lerpParameter );
}
The setup for this isn't too hard. Your progress bar needs to have a gradient alpha channel that fades from white to black (or black to white depending on which way you look at it ;) ). Then as time goes on, progressively more of the texture will be visible and you will have a progress bar.
in my game i already have a texture called magical spell bar is there when player score increase the health of the player also increase in magical spell bar as yellow texture so i used above code i can i use draw texture to increase the health of the player when he get score in magical spell bar which is in rectangular shape in upwards direction(- y direction) from bottom to top direction
Your answer
Follow this Question
Related Questions
How to create a vertical circular progress bar 1 Answer
Problem ProgressBar with health + Time the poison 1 Answer
Progress of loading level 1 Answer
Modify circular progress bar based on a value? 1 Answer
Progress Bar 2 Answers