- Home /
Question by
joshbanks88 · Mar 19, 2013 at 08:33 PM ·
guibuttonbegingroup
GUI button disappears in GUI group
when i added GUI.BeginGroup(Rect(240,440,164,219))
around one of my buttons i lost one of my buttons. Is there a reason it just disappears or would something else cause this to happen?
function BuildBoard()
{
var SmallerNum:int;
GUI.BeginGroup(Rect(240,0,164,219));
GUILayout.Box(Resources.Load("back"), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216));
GUI.EndGroup();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Box(Resources.Load(p1War), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216));
GUILayout.Box(Resources.Load(p1Card), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216));
GUILayout.Box(Resources.Load(p2Card), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216));
GUILayout.Box(Resources.Load(p2War), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUI.BeginGroup(Rect(240,440,164,219));
//If the Player clicks on there button it begins to compare the cards flipped
if(GUILayout.Button(Resources.Load("back"), GUILayout.MaxWidth(160),GUILayout.MaxHeight(216)))
{
//Debug.Log("the value of Player one card: " + playerOneCards[0].CardValue);
//Debug.Log("the value of Player two card: " + playerTwoCards[0].CardValue);
p1War = "";
p2War = "";
//removes card from the array.
Flipped1.RemoveAt(0);
Flipped2.RemoveAt(0);
Flipped1.Add(playerOneCards[0]);
Flipped2.Add(playerTwoCards[0]);
//removes card from the array.
playerOneCards.RemoveAt(0);
playerTwoCards.RemoveAt(0);
Debug.Log(Flipped1[0].CardValue);
Debug.Log(Flipped2[0].CardValue);
p1Card= Flipped1[0].img;
p2Card= Flipped2[0].img;
//checks to see if the Cards are equal
if(Flipped1[0].CardValue != Flipped2[0].CardValue)
{
// check to see who wins the cards if cards are not equal
if(Flipped1[0].CardValue < Flipped2[0].CardValue)
{
playerTwoCards.Add(Flipped1[0]);
playerTwoCards.Add(Flipped2[0]);
//Debug.Log("cards go to Player2");
}
else
{
playerOneCards.Add(Flipped2[0]);
playerOneCards.Add(Flipped1[0]);
}
}
else
{
while(Flipped1[Flipped1.length-1].CardValue == Flipped2[Flipped2.length-1].CardValue)
{
if(playerOneCards.length >= 3 || playerOneCards.length >= 3 )
{
for(var i= 0; i < 3; i++)
{
//adds a card from the players hand to the flipped pile
Flipped1.Add(playerOneCards[0]);
Flipped2.Add(playerTwoCards[0]);
//removes card from the array.
playerOneCards.RemoveAt(0);
playerTwoCards.RemoveAt(0);
}
p1War = Flipped1[Flipped1.length-1].img;
p2War = Flipped2[Flipped2.length-1].img;
Debug.Log(i);
}
else
{
if(playerOneCards.length < playerTwoCards.length)
{
SmallerNum = playerOneCards.length;
}
else
{
SmallerNum = playerTwoCards.length;
}
for(var q= 0; q < playerOneCards.len0gth; q++)
{
//adds a card from the players hand to the flipped pile
Flipped1.Add(playerOneCards[0]);
Flipped2.Add(playerTwoCards[0]);
//removes card from the array.
playerOneCards.RemoveAt(0);
playerTwoCards.RemoveAt(0);
}
p1War = Flipped1[Flipped1.length-1].img;
p2War = Flipped2[Flipped2.length-1].img;
Debug.Log(i);
}
}
if(Flipped1[i].CardValue < Flipped2[i].CardValue)
{
while (Flipped1.length != 0||Flipped2.length != 0)
{
playerTwoCards.Add(Flipped1[0]);
playerTwoCards.Add(Flipped2[0]);
//removes card from the array.
Flipped1.RemoveAt(0);
Flipped2.RemoveAt(0);
}
}
else
{
while (Flipped1.length != 0||Flipped2.length != 0)
{
playerOneCards.Add(Flipped2[0]);
playerOneCards.Add(Flipped1[0]);
//removes card from the array.
Flipped1.RemoveAt(0);
Flipped2.RemoveAt(0);
}
}
Flipped1.Add("");
Flipped2.Add("");
}
Debug.Log("the # of cards in Player one hand: " + playerOneCards.length);
Debug.Log("the # of cards in Player one hand: " + playerTwoCards.length);
Debug.Log(playerOneCards.length + playerTwoCards.length);
//Checks to see if Game is over
if(playerOneCards.length == 0||playerTwoCards.length == 0)
{
ifGameOver=true;
Debug.Log("player one lose");
}
}
GUI.EndGroup();
}
Comment
Answer by Zamaroth · Mar 19, 2013 at 09:10 PM
did you end that group with GUI.EndGroup()?
GUI.BeginGroup(Rect(240,440,164,219));
GUI.Button(Rect(0,0,100,100));
GUI.EndGroup();
updated question with my code but i did have GUI.EndGroup();
Your answer
![](https://koobas.hobune.stream/wayback/20220613094720im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Button then instanitates gameobject 1 Answer
How to hook up the particle system to jump animation? 1 Answer
Make more buttons appear, on button click. 1 Answer
Null reference exception[SOLVED] 1 Answer
GUI Button Animation Cue 1 Answer