In my game i need to call sprite at run time . For example i have a sprite sheet of progress bar and progress bar sprite is sliced into 11 slice. How to call each slice at run time
I would recommend you set it up as a spritesheet in Unity(Set sprite to multiple and slice it) and then use an animation where you manually progress it to the next frame when you need it to.
Check out: Creating 2D animated sprites using Unity 4.3 by Michael H.C. Cummings
Create an anim tree with the sprites. Each animation is a level in the progress bar. You should have animations for each of the levels in the progress bar.
To display any level in progress bar all you have to do is play the correct animation.
But why not put a white sprite above this blue progress bar and scale it?
You will have very smooth control that way …
Hi, you can just display a certain bar depending of time:
private IEnumerator ProgressBar(float time = 2f)
{
float startingTime = Time.time;
float elapsedTime = Time.time;
float stopTime = 1f / time;
int barID = 0;
while(barID < 10)
{
if((elapsedTime - startingTime) >= 1)
{
barID++;
startingTime = elapsedTime;
}
elapsedTime += Time.fixedDeltaTime * stopTime;
yield return null;
}
}
Where “barID” is the id in your array or in the spritesheet of the bar you want to display