Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RichCoggin · Jul 24, 2013 at 03:15 PM · buttonmenubuttonsnavigationitween

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;
     
     }
 }
 
 
 
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sfc.itzhak · Jul 24, 2013 at 04:25 PM 0
Share

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

avatar image RichCoggin · Jul 24, 2013 at 05:29 PM 0
Share

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

avatar image sfc.itzhak · Jul 24, 2013 at 05:43 PM 0
Share

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

avatar image RichCoggin · Jul 24, 2013 at 07:39 PM 0
Share

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

avatar image sfc.itzhak · Jul 25, 2013 at 07:19 AM 0
Share

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;
  
     }
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RichCoggin · Jul 25, 2013 at 02:04 PM 0
Share

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

avatar image sfc.itzhak · Jul 25, 2013 at 02:19 PM 0
Share

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

avatar image RichCoggin · Jul 25, 2013 at 04:21 PM 0
Share

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

avatar image sfc.itzhak · Jul 26, 2013 at 09:50 AM 0
Share

if the answers fit please mark as answered

avatar image RichCoggin · Jul 26, 2013 at 10:46 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges