GUI Button which looks like a Toggle

Hi folks,

I'd like to make a button which looks like a toggle, that can perform a series of commands when clicked, and updates the checkbox to appear checked or unchecked.

In other words, I'd like to be able to click on something that looks like a toggle button and have it call a function or two and update the toggle button's status.

But I can't figure out how to make a button which looks like a toggle also update the toggle status and still perform commands when clicked. Here are some things I've tried:

// this always looked unchecked and doesn't do anything when clicked
toggle = GUILayout.Button("Invert Button", "toggle");

// this does something when clicked but still always looks unchecked          
if (GUILayout.Button("Invert Vertical Camera Movement", "toggle")) {
    toggle = !toggle;

// this obviously doesn't work
toggle = if (GUILayout.Button("Invert Vertical Camera Movement", "toggle")) {
    toggle = !toggle;

How can this be done?

If there's no way to do it then what's the point in being able to make a button look like a toggle box if you can't get it to show the status of the toggle?

more ▼

asked Apr 05 '12 at 08:59 PM

Deozaan gravatar image

62 1 3 4

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 05 '12 at 08:59 PM

Seen: 785 times

Last Updated: Apr 05 '12 at 09:10 PM