Hi all,
Im trying to put together a whole bunch of UI to do with dice for some coursework, and I got problems that are doing my head in.
using UnityEngine;
using System.Collections;
public class Master : MonoBehaviour {
int state = 0;
// State Description Goes Here (read in russian accent, sounds orrsom!)
/*
* 0 The app has been started. this is the intro screen displays Info on what to do and what App does
*
* */
Texture2D BigRedButton;
GUIContent IntroButton;// = new GUIContent("Proceed", BigRedButton, "Takes you to main Option Screen");
Rect DiceGroup, ResultsGroup,
D4Rect, D6Rect, D8Rect, D10Rect,
D12Rect, D20Rect, D100Rect, RollDiceRect,
CalcProbRect, ConditionRect, ProbRect;// Rects for all the buttons/groups
// Use this for initialization
void Start ()
{
ButtRect = new Rect( (float)((Screen.width/2)- (Screen.width*0.1)), //left
(float)((Screen.height/2) - (Screen.height*0.1)), //top
(float)(Screen.width*0.2), // width
(float)(Screen.height*0.2));// height
DiceGroup = new Rect( 0.0f, //left
(float)(Screen.height*0.8),//top
(float)Screen.width, //width
(float)(Screen.height*0.2));//height
ResultsGroup = new Rect( 0.0f, //left
0.0f, //top
(float)(Screen.width*0.75), // width
(float)(Screen.height*0.3));// height
ProbRect = new Rect( (float)(Screen.width*0.75), //left
0.0f, //top
(float)(Screen.width*0.75f), // width
(float)(Screen.height*0.3f));// height
D4Rect = new Rect((float) (Screen.width*0.125), //left
(float)(Screen.height*0.5),
(float)(Screen.width*0.125),
(float)(Screen.height*0.5));
}
// Update is called once per frame
void Update ()
{
switch(state)
{
case 0:
ButtRect = new Rect((float)((Screen.width/2)- (Screen.width*0.1)), //left
(float)((Screen.height/2) - (Screen.height*0.1)), //top
(float)(Screen.width*0.2), // width
(float)(Screen.height*0.2));// height
// Check Left Click
if (Input.GetMouseButtonDown(0) ButtRect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
{
//Actions on Left Click
state = 1;
}
// Check Right Click
if (Input.GetMouseButtonDown(1) ButtRect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
{
//Actions on Right Click
}
break;
case 1:
DiceGroup = new Rect(0.0f, //left
(float)(Screen.height*0.8),//top
(float)Screen.width, //width
(float)(Screen.height*0.2));//height
ResultsGroup = new Rect(0.0f, //left
0.0f, //top
(float)(Screen.width*0.75), // width
(float)(Screen.height*0.3));// height
ProbRect = new Rect((float)(Screen.width*0.75), //left
0.0f, //top
(float)(Screen.width*0.25f), // width
(float)(Screen.height*0.3f));// height
D4Rect = new Rect( (float)(Screen.width*0.125), //left
(float)(Screen.height*0.5),// top
(float)(Screen.width*0.125),//width
(float)(Screen.height*0.5));//height
break;
case 2:
break;
}
}
Rect ButtRect;
void OnGUI()
{
switch(state)
{
case 0:
GUI.Button(ButtRect, "MyButton");
break;
case 1:
GUI.Box (new Rect( 0.0f, //left
(float)(Screen.height*0.8),//top
(float)Screen.width, //width
(float)(Screen.height*0.2)),// height
"Dice");
GUI.BeginGroup (DiceGroup);// THE DICE GROUP BOX
GUI.Button(D4Rect, "D4");
GUI.EndGroup ();
GUI.Box(new Rect( 0.0f, //left
0.0f, //top
(float)(Screen.width*0.75), // width
(float)(Screen.height*0.3)),// height
"Results");
GUI.BeginGroup(ResultsGroup);// THE RESULTS GROUP BOX
GUI.EndGroup();
GUI.Box (new Rect( (float)(Screen.width*0.75), //left
0.0f, //top
(float)(Screen.width*0.25f), // width
(float)(Screen.height*0.3f)), // height
"Probablity");
GUI.BeginGroup(ProbRect);//PROBABLITY BOX
GUI.Button(new Rect(0,0, 50,50), "lol");
GUI.EndGroup();
break;
case 2:
break;
}// End Switch State
//GUI.Button(new Rect( (float)((Screen.width/2)- (Screen.width*0.1)), (float)((Screen.height/2) - (Screen.height*0.1)), (float)(Screen.width*0.2), (float)(Screen.height*0.2)), IntroButton);
}//End OnGUI
}//End Class
hope the code tags worked, first time I used em.
Now the bit that says “GUI.Button(D4Rect, “D4”);” doesnt work. Nothing draws no matter what rect I use or what text I put into that line.
But the lol button works a few lines later.
Also, I had issues where if I drew a box with a label saying “Dice Group” for example, and I did that inside the group, telling it to fill the groups coordinates, the label would centre on the screens resolution and not the groups resolution, so if I drew the group on the right side the text would never show up, but if I draw a button with the exact same rect and text it draw exactly as its supposed to.
Thats the lol button.
Everything im using is initialised in start, updated in update and drawn by OnGUI.
OK, so anyone know wtf is up? i been bashing my head off these inconsistent errors for 3 days now and I’m on the verge of starting from scratch in XNA cause that frickin works.
Sorry for being frustrated but 3 days and I can’t even get the 1 line buttons to draw.