- Home /
Horizontal Bar
I'm brazilian and my english is basic.
I'm building a racing game for android. I already created an horizontal bar, but I need to customize its. I need to increase its height and width. I increase its height on GUI, but it display the same small scale in-game.
I need to make a funcionality too. The player will scroll this bar to move the car around. But when this bar is not pressed, I want it get back to value = 0.
Can anyone help me with the scale and the funcionality.
Code:
static var HoriGUI : float = 0.0;
static var HoriAll : float = 0.0;
HoriGUI = GUI.HorizontalSlider (Rect (150, 650, 150, 75), HoriAll, -1.0, 1.0);
Thx for the attention.
Answer by fafase · Jan 07, 2013 at 12:45 PM
There you go:
using UnityEngine;
using System.Collections;
public class GUIScript : MonoBehaviour {
public float hSliderValue;
void OnGUI()
{
if (Input.GetMouseButton(0))
{
hSliderValue = GUILayout.HorizontalSlider(hSliderValue, -1.0F, 1.0F,GUILayout.Width(100));
}
else
hSliderValue = GUILayout.HorizontalSlider(0, -1.0F, 1.0F,GUILayout.Width(100));
GUILayout.Label(hSliderValue.ToString());
}
}
Values go from -1 to 1 but it is up to you to modify this.
Thx for the answer, but the game is for android. How can I 'convert' the mouse press by the touch screen holding?
$$anonymous$$ouseButton works on touch, thank you very much.