- Home /
iTween issue creating a gui. menu box
Hi there, I'm having a little problem with creating a gui menu using iTween. I tried to convert an example from the site for a button move as I want the menu box (with buttons) to move from left to right over x distance; a sliding menu if you like.
I get an error: error CS0029: Cannot implicitly convert type void' to
bool'
Can't quite get my head around why this is. I am quite new to this, so may have things a little 'round the wrong way. Any thoughts would be appreciated. Here's my code so far:
using UnityEngine;
using System.Collections;
public class AnimatingUnityGUI : MonoBehaviour
{
//Selection Grid
public int selGridInt = -1;
public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4", "Grid 5", "Grid 6", "Grid 7", "Grid 8", "Grid 9"};
//Counts sells
private int lastSel = -1;
//LeftNav GUI skin reference
public GUISkin leftnav;
//Objects
public GameObject Object1;
public GameObject Object2;
//Box size and state
public bool boxRectState = false;
public Rect boxRect = new Rect(-5,14,100,800); //holds actual button rect coordinates
public Rect initialPosition = new Rect(0,20,100,55); //holds starting rect coordinates
public Rect activePosition = new Rect(75,130,100,55); //holds ending rect coordinates
void OnGUI()
{
//GUISkin for Group
GUI.skin = leftnav;
GUI.BeginGroup(boxRect, "","Box");
///THIS IS THE ERROR LINE//AnimatingUnityGUI.cs(36,17): error CS0029: Cannot implicitly convert type `void' to `bool'///
if(GUI.BeginGroup(boxRect,"","Box"))
{
if(boxRectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",initialPosition,"onupdate","MoveBox","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",activePosition,"onupdate","MoveBox","easetype","easeinoutback"));
}
boxRectState = !boxRectState;
// Buttons for GUI box
selGridInt = GUI.SelectionGrid(new Rect(14, 25, 100, 800), selGridInt, selStrings, 1);
if (selGridInt != lastSel)
{ // selGridInt changed?
lastSel = selGridInt; // yes: update lastSel and take appropriate action
if (selGridInt == 0)
{
GameObject objObject2 = (GameObject)Instantiate(Object2, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object1"));
}
else if (selGridInt == 1)
{
GameObject objObject1 = (GameObject)Instantiate(Object1, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object2"));
}
}
}
GUI.EndGroup();
}
void MoveboxRect(Rect newCoordinates){
boxRect=newCoordinates;
}
}
you are using if on that line and GUI.BeginGroup is not a true or false nor its not a button.
so it tells you the if statement is an error.
http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginGroup.html
good luck sfc
Do you mean it has to be more like this, although it still has the same error:
GUI.BeginGroup(new Rect(10, 10, 100, 600));
GUI.Box(new Rect(-5, 14, 100, 800), "");
if(GUI.Box(new Rect(-5, 14, 100, 800), ""))
...
Cheers sfc
why are you using IF with GUI.Box use GUI.Button and it shuld be ok
gui.box is a void static function while gui.button is a bool
static function Box(position: Rect, text: string): void; http://docs.unity3d.com/Documentation/ScriptReference/GUI.Box.html
static function Button(position: Rect, text: string): bool;
http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html
have fun
sfc
So I guess this is where I was getting mixed up. I wanted to be able to touch the gui.box and the action would be it would slide out. Can the box be touched and allow the slide out function?nimagine the edge of the box had a message that said touch to open.
Thanks again
Rich
just change the box to button, try this
using UnityEngine;
using System.Collections;
public class AnimatingUnityGUI : $$anonymous$$onoBehaviour
{
//Selection Grid
public int selGridInt = -1;
public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4", "Grid 5", "Grid 6", "Grid 7", "Grid 8", "Grid 9"};
//Counts sells
private int lastSel = -1;
//LeftNav GUI skin reference
public GUISkin leftnav;
//Objects
public GameObject Object1;
public GameObject Object2;
//Box size and state
public bool boxRectState = false;
public Rect boxRect = new Rect(-5,14,100,800); //holds actual button rect coordinates
public Rect initialPosition = new Rect(0,20,100,55); //holds starting rect coordinates
public Rect activePosition = new Rect(75,130,100,55); //holds ending rect coordinates
void OnGUI()
{
//GUISkin for Group
GUI.skin = leftnav;
GUI.BeginGroup(boxRect, "","Box");
///THIS IS THE ERROR LINE//AnimatingUnityGUI.cs(36,17): error CS0029: Cannot implicitly convert type `void' to `bool'///
if(GUI.Button(boxRect,""))
{
if(boxRectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",initialPosition,"onupdate","$$anonymous$$oveBox","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",activePosition,"onupdate","$$anonymous$$oveBox","easetype","easeinoutback"));
}
boxRectState = !boxRectState;
}
// Buttons for GUI box
selGridInt = GUI.SelectionGrid(new Rect(14, 25, 100, 800), selGridInt, selStrings, 1);
if (selGridInt != lastSel)
{ // selGridInt changed?
lastSel = selGridInt; // yes: update lastSel and take appropriate action
if (selGridInt == 0)
{
GameObject objObject2 = (GameObject)Instantiate(Object2, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object1"));
}
else if (selGridInt == 1)
{
GameObject objObject1 = (GameObject)Instantiate(Object1, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object2"));
}
}
GUI.EndGroup();
}
void $$anonymous$$oveboxRect(Rect newCoordinates){
boxRect=newCoordinates;
}
}
Answer by sfc.itzhak · Jul 25, 2013 at 12:12 PM
just to put all in 1 answer:
1.the itween is callin MoveBox onupdate and you function is called MoveboxRect; 2.just change the box to button, try this
using UnityEngine;
using System.Collections;
public class AnimatingUnityGUI : MonoBehaviour
{
//Selection Grid
public int selGridInt = -1;
public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4", "Grid 5", "Grid 6", "Grid 7", "Grid 8", "Grid 9"};
//Counts sells
private int lastSel = -1;
//LeftNav GUI skin reference
public GUISkin leftnav;
//Objects
public GameObject Object1;
public GameObject Object2;
//Box size and state
public bool boxRectState = false;
public Rect boxRect = new Rect(-5,14,100,800); //holds actual button rect coordinates
public Rect initialPosition = new Rect(0,20,100,55); //holds starting rect coordinates
public Rect activePosition = new Rect(75,130,100,55); //holds ending rect coordinates
void OnGUI()
{
//GUISkin for Group
GUI.skin = leftnav;
GUI.BeginGroup(boxRect, "","Box");
///THIS IS THE ERROR LINE//AnimatingUnityGUI.cs(36,17): error CS0029: Cannot implicitly convert type `void' to `bool'///
if(GUI.Button(boxRect,""))
{
if(boxRectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",initialPosition,"onupdate","MoveBox","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",activePosition,"onupdate","MoveBox","easetype","easeinoutback"));
}
boxRectState = !boxRectState;
}
// Buttons for GUI box
selGridInt = GUI.SelectionGrid(new Rect(14, 25, 100, 800), selGridInt, selStrings, 1);
if (selGridInt != lastSel)
{ // selGridInt changed?
lastSel = selGridInt; // yes: update lastSel and take appropriate action
if (selGridInt == 0)
{
GameObject objObject2 = (GameObject)Instantiate(Object2, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object1"));
}
else if (selGridInt == 1)
{
GameObject objObject1 = (GameObject)Instantiate(Object1, new Vector3(0,0,0), transform.rotation);
Destroy (GameObject.FindWithTag("Object2"));
}
}
GUI.EndGroup();
}
void MoveBox (Rect newCoordinates){
boxRect=newCoordinates;
}
}
have fun
SFC
That's great. it's working! thanks. one final thing, because the touch area is now a button, it associates itself with the button gui skin. Is there a way to disable that as I don't want it to show up? I can't find it's reference to skin in the inspector if that makes sense. I guess what would be great is to understand how you can skin the buttons separately in a selection grid. $$anonymous$$any thanks for your patience and time.
Rich
Hey take a look here http://docs.unity3d.com/Documentation/Components/class-GUIStyle.html
On my phone if you want a more detailed answer it will take a bit
Sfc
Thanks for the offer! I'm gonna look through the docs in some detail and try to get my head around it a little more, but if I can't crack it, I's defo be up for a chat.
Cheers
Hey,
One last question. I got the custom buttons working which is cool. the thing I'm wrestling with is the parameters that the menu panel moves. I'm trying to get the menu to half way off the page on the left. When the area is touched it moves in. Problem is, is that every time I set it to a $$anonymous$$us position, the 'live' touch area disappears, or when touched it moves completely out of screen. Any ideas how to set the parameters. $$anonymous$$any thanks and hopefully last one for now!
Rich
Your answer
Follow this Question
Related Questions
Pause menu not working 1 Answer
A button inside of a button is highlighting parent button 1 Answer
UI Buttons - affects all 0 Answers
Button highlighted a pushable without touching it 0 Answers
Missing 'Options' in my GUI Menu? 2 Answers