6
\$\begingroup\$

I have created a progress bar inside Unity for one of my energy systems. The bar progression works fine. Its just a plane pivoted on one of the faces so scaling it in x axis makes it progress further as seen in the image belowenter image description here Now I am trying to implement a feature where when the bar stops progressing I would want to show a red bar indicating that it has stopped like in the image below

enter image description here To implement this I would need to know somehow that the bar has stopped scaling and not progressing any further so that I can put the red bar at the position where it stops scaling.

But how do I know when the yellow progress bar stops progressing as its position stays the same throughout and its just scaling in the x direction.

I hope my question makes sense. Please help me out if it does. Thanks :)

\$\endgroup\$
4
  • \$\begingroup\$ why not translate based on the progression \$\endgroup\$ Commented Nov 15, 2014 at 0:49
  • \$\begingroup\$ Could you please be more specific as to how do I make a solid bar progress with just translation? \$\endgroup\$
    – ckzilla
    Commented Nov 15, 2014 at 1:35
  • \$\begingroup\$ By translate, think he's referring to translating the scale of the object. \$\endgroup\$
    – Mike Hunt
    Commented Jan 14, 2016 at 12:53
  • \$\begingroup\$ You're looking for: size_of_object_in_units * current_scale / default_scale \$\endgroup\$ Commented Jun 29, 2017 at 20:12

4 Answers 4

1
\$\begingroup\$

Take a look at Renderer Bounds

Which gives you a world space AABB that you can use to determine the scale along the axis.

Now if you have a rotated loading bar you can just use the transform's lossyscale to do a similar thing but the rotation will make it slightly inaccurate.

Once you know the scale along an axis you can use an origin point to define an offset from the origin point where your red bar should appear.

I have included this poorly drawn image to help.

Offset from origin example

\$\endgroup\$
0
\$\begingroup\$

If I understand your problem correctly, it is as follows:

Problem: You have no way of knowing when your progress bar stops scaling/progressing in x value. You would like to position a red bar (for player feedback) at the end of the progress bar only if it stops scaling/progressing.

If this is correct, I think that I may be able to help.

Answer: It seems as though you are in need of a "status bool". Status bools are very important when you are trying to record and communicate binary states (Ex. on/off) to other scripts. I am not sure if you have a separate script that controls the function of the red bar, but the method should be similar:

private bool isScaling = false; // Assuming that the bar defaults with no scaling.

void Update () { // Update function is used in this example for testing purposes only.
    if (isScaling) {
        // The red bar is not visible.
    } else {
        // The red bar is visible.
    }
};

That line of thinking will work for knowing when to show or hide the red bar. The other problem that you will face is actually setting the 'isScaling' bool to the correct value at the appropriate times. For that, you will probably need to create (or modify) a function that sets 'isScaling' to 'true' when you are scaling the bar and to false when you are not. I hope this helps!

\$\endgroup\$
2
  • \$\begingroup\$ The problem is not finding out if the bar is scaling or not. The problem is finding the position of the transform point when the progress or the scaling stops in the x direction. I am not translating the bar but just scaling it in x direction so there is no way for me to find its position when its scaled. \$\endgroup\$
    – ckzilla
    Commented Nov 15, 2014 at 23:21
  • \$\begingroup\$ @ckzilla if you parent your red bard with the correct offset to the plane it should move with it. Then when the scaling stoppes just make it visible. \$\endgroup\$
    – Uri Popov
    Commented May 16, 2016 at 10:21
0
\$\begingroup\$

As Jackoftraes said you want to have a bool for displaying if the bar should be displayed.

So you don't know if it moves by the position but you do know if the scale changes. So every frame check if the scale is the same as last frame (or the past few frames), then once the scale has been the same for enough frames show the red bar.

Hope this helps :) (even though i'm late to the party)

\$\endgroup\$
0
\$\begingroup\$

You could use a slider, if you need more option for the sliders then 0.x to 1.x then you can set the max and min value to whatever you like. You can set a bool on this and say if value in changing bool is true, and make an IEnumerator wait x seconds, and then show the slider handle after that time.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .