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 Tyler 2 · Dec 11, 2010 at 10:43 PM · compile-errortoolbar

How do I use a toolbar?

Hello. How do I use the toolbar GUI in unity? I know how to display the buttons, but how to I make them affect something? I have tried something like this: (and it does not work)

EDIT: I changed the Static var Mode=float to "static var Mode = 5;"(I used 5 because I am only using 0-4 in the other script, bit I guess that doesn't really matter, I also tried using the " : float" thing and I am getting no errors. Anyways, I still have into a somewhat hard to explain problem.

If I define something to happens in the script that has the toolbat GUI like this, the other variable (in this case, "Score") works. Its changed to whatever is defined.

if (ModeInt==2) {Stats.Score=1000}

I then try to make a variable in the GUI script affect a variable in the "ArcadeOptions" script:

if (ModeInt==0) {ArcadeOptions.Mode =2;}

Here is the ArcadeOptions Script

static var Mode = 5;
if (Mode ==0) {Stats.Score=1000;}
and it works, the Score value is changed. 

The problem happens when I try to have the "ModeInt==" something other than 0(so that other buttons can affect the "ArcadeOptions" script). No matter what the element of that toolbar is, if it is not 0, nothing happens in the other script, what is going on(I am getting no errors from unity)?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Statement · Dec 11, 2010 at 11:12 PM

Seems you're testing the string array instead of the selected item number.

function Update()
{
    if (ModeStrings == 2) // Error
        ArcadeOptions.Mode = 2;
}

If you change that to this, I'm sure you'll be fine.

function Update()
{
    if (ModeInt == 2) 
        ArcadeOptions.Mode = 2;
}

You have further errors:

static var Mode = float; // Error static var Mode : float; // Ok

// and...

function Update() { if (ModeInt = 2) ArcadeOptions.Mode = 2; // Bug if (ModeInt == 2) ArcadeOptions.Mode = 2; // OK }


See the manual on gui controls (quote) for further info:

Toolbar

The Toolbar Control is essentially a row of Buttons. Only one of the Buttons on the Toolbar can be active at a time, and it will remain active until a different Button is clicked. This behavior emulates the behavior of a typical Toolbar. You can define an arbitrary number of Buttons on the Toolbar.

Basic Usage

The active Button in the Toolbar is tracked through an integer. You must provide the integer as an argument in the function. To make the Toolbar interactive, you must assign the integer to the return value of the function. The number of elements in the content array that you provide will determine the number of Buttons that are shown in the Toolbar.

/* GUI.Toolbar example */

var toolbarInt = 0; var toolbarStrings : String[] = ["Toolbar1", "Toolbar2", "Toolbar3"];

function OnGUI () { toolbarInt = GUI.Toolbar (Rect (25, 25, 250, 30), toolbarInt, toolbarStrings); }

And further down:

GUI.changed

To detect if the user did any action in the GUI (clicked a button, dragged a slider, etc), read the GUI.changed value from your script. This gets set to true when the user has done something, making it easy to validate the user input.

A common scenario would be for a Toolbar, where you want to change a specific value based on which Button in the Toolbar was clicked. You don't want to assign the value in every call to OnGUI(), only when one of the Buttons has been clicked.

Basically you must check if (GUI.changed) if any change was done immediately after your toolbox.

Comment
Add comment · Show 7 · 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 Tyler 2 · Dec 12, 2010 at 12:09 AM 0
Share

Thanks. I changed it to $$anonymous$$odeInt and I get this error Assets/Scripts/$$anonymous$$enu/Arcade.js(33,45): BCE0022: Cannot convert 'int' to 'System.Type'. Tyler 43 $$anonymous$$s ago

avatar image Statement · Dec 12, 2010 at 12:17 AM 0
Share

What is "ArcadeOptions.$$anonymous$$ode" ?

avatar image Tyler 2 · Dec 12, 2010 at 12:31 AM 0
Share

$$anonymous$$ode is a variable located in a seperate script called "ArcadeOptions". These are the scripts for the selecting the options for my game (mode, difficulty, etc.). How it works is that the menu is a bunch of toolbars. Each toolbar option selected represents a number, that number represents a number in a different script, which contains the functions that start the options (like "Standard difficulty=true"). I will add the scripts in my edited question.

avatar image Statement · Dec 12, 2010 at 12:52 PM 0
Share

Btw, another error. In your update function you have if ( $$anonymous$$odeInt = 2 ), it should use == not =. And please number your lines or something when you are posting an error message. Assets/Scripts/$$anonymous$$enu/Arcade.js(33,45) says the error is on line 33, column 45 in Arcade.js. I can't possibly know if your code is from that range.

avatar image Statement · Dec 12, 2010 at 12:56 PM 0
Share

static var $$anonymous$$ode = float; That's the error. static var $$anonymous$$ode : float; it should be.

Show more comments

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

No one has followed this question yet.

Related Questions

Toolbar question... 1 Answer

Does every object have to be static when adding tool bars to Unity? 0 Answers

NotificationCenter (from the community wiki) problem 1 Answer

Keep getting a "Failed to retrieve assembly" error in VS, while the game runs just fine? 1 Answer

Can't compile extension method in a plugin. 0 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