I have been making a script for a progress bar and it works fine other than it starts in the centre then pushes out left and right. I want the bar to start left and move right till it fills then let the button spawn and be click able. any help would be great.
My script:
#pragma strict
public var player: Player;
private var currentProgress:double = 0;
private var caseValueM:double = 1.50;
private var caseValueF:double = 1.50;
public var solveButtonActive:boolean = false;
public var solveButton:GameObject;
public static var solveButtonPressed:boolean = false;
You are not using GUI elements here if I understand…
I think the best way to do a ProgressBar is a simple GUI elements. I’m not familiar with Unity 4.6 GUI but I often use the GUI class and functions in my MonoBehaviours to display my 2D UI.
To achieve a progressbar, this is really simple with this class ! Here is a sample of how to draw a ProgressBar in GUI (C#) :
private static GUIStyle ProgressBarBackground = new GUIStyle();
private static GUIStyle ProgressBarContent = new GUIStyle();
private bool ProgressBarStylesInit = false;
public static void InitStyles() {
// Put here your styles values;
ProgressBarStylesInit = true;
}
public static void ProgressBar(float _width, float _height, int _value, int _max, params GUILayoutOption[] _options) {
if (!ProgressBarStylesInit)
InitStyles();
_value = Mathf.Clamp(_value, 0, _max);
GUILayout.BeginHorizontal(_options);
GUILayout.Label("", ProgressBarBackground, GUILayout.Width(_width));
GUILayout.Space(-_width - ProgressBarBackground.margin.left);
GUILayout.Label("", ProgressBarContent, GUILayout.Width(Mathf.CeilToInt(_width * _value / (float)_max)));
GUILayout.Space(_width - Mathf.CeilToInt(_width * _value / (float)_max));
GUILayout.EndHorizontal();
}
When you know how to use the GUI class, this become simple to add a button when it’s full, and do what you want.