mandag den 5. april 2010

Simple GUI scripting

Since our project is about making an infotainment system, controlled by using a touch screen, we had the need for a simple GUI (Graphical User Interface) to be used in the demo for the Midterm Seminar tomorrow at the university.

We wanted the buttons to be centered horizontally and vertically in a "+"-shape in order to make the GUI intuitive, regarding the movement: Up, Down, Right, Left.

In order to center the "Up"-button horizantally, we used the (Screen.width divided by 2) minus 50 (half the size of the button rectangle).

(GUI.RepeatButton (Rect (((Screen.width)/2)-50,10,100,100), "Up"))
The same principle was used on the other buttons.

The picture above shows the 4 menu buttons in a test scene. Each of the buttons will make the camera move in it's direction when pushed.
Next step will be to make a custom design for the GUI-elements.

The code for the 4 buttons and the movement of the camera:
function OnGUI () {
if (GUI.RepeatButton (Rect (((Screen.width)/2)-50,10,100,100), "Up")) {
transform.Translate (0,0,0.5);
}
if (GUI.RepeatButton (Rect (((Screen.width)/2)-50,(Screen.height)-110,100,100), "Down")) {
transform.Translate (0,0,-0.5);
}
if (GUI.RepeatButton (Rect (10, ((Screen.height)/2)-50, 100, 100), "Left")) {
transform.Translate (-0.5,0,0);
}
if (GUI.RepeatButton (Rect (Screen.width-110, ((Screen.height)/2)-50, 100, 100), "Right")) {
transform.Translate (0.5,0,0);
}
}

Ingen kommentarer:

Send en kommentar