• Unity
  • Services
  • Showcase
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Showcase
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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 Towtow10 · Jan 02 at 08:48 AM · buttoncanvas

Show and hide a canvas on a button click.

I have two canvases in my scene one is for the main menu. It has play, options and quit buttons. I would like it that when I click the options button it shows a second canvas, that starts of hidden, how would I do this?

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

2 Replies

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

Answer by AlanGreyjoy · Jan 03 at 01:52 AM

You can also click the plus sign on OnClick, and drag over that panel. Then on the down arrow select GameObject.SetActive

Un checked is false and Check is true.

Whatever panel you want to start off hidden, then you just uncheck it from the very very top of the inspector.

No code needed.

Once you need code, then you need to learn enums and switch statements. :)

Comment
Add comment · Show 1 · 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 Towtow10 · Jan 03 at 02:21 AM 0
Share

Thanks, this was all I needed.

avatar image
1

Answer by Gooren · Jan 02 at 09:24 AM

Select button in the Inspector. On the very bottom, You have OnClick() handlers. There You can reference method of some component on specific GameObject. So use it to reference method that will know about/be able to to find both Your canvases and then You will say something like:

 CanvasA.gameObject.SetActive(false);
 CanvasB.gameObject.SetActive(true);
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 Towtow10 · Jan 02 at 09:30 PM 0
Share

What i did is i created a new script put CanvasA.gameObject.SetActive(false); under void Start () { i then attached that to an empty game object, which i then set the OnClick() to that game object, where do i specify which canvas i want to disapear?

avatar image ShadyProductions Towtow10 · Jan 02 at 09:56 PM 0
Share
 CanvasA.gameObject.SetActive(false);

means disabling CanvasA. So you already specified it.?

I would also not put it in the start function, because that is run as soon as the game starts. What Gooren ment, is to make a new method and link it to the OnClick() handler.

Like so:

     void disableCanvas() {
             CanvasA.SetActive(false);
     }
 
     void enableCanvas() {
             CanvasA.SetActive(true);
     }

If you wish to do it through scripting and not use the OnClick() handlers you could go for this:

 void changeCanvasProperty(GameObject yourCanvas, bool disable) {
     if (!disable)
         yourCanvas.SetActive(false);
     else
         yourCanvas.SetActive(true);
 }

This way you can use it as follows: changeCanvasProperty(CanvasA, false);

avatar image Towtow10 ShadyProductions · Jan 02 at 11:42 PM 0
Share

sorry I'm not very good at c#, I don't quite understand what I'm supposed to do, this might be asking a bit too much but could some one take me through a step by step process? The canvas is called options.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a user guide.

If you are a new user, check out our FAQ for more information.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

For troubleshooting common problems with Unity 5.x Editor (including Win 10).

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

UI button dosent show function 1 Answer

Canvas Button persistence 0 Answers

Right click listener - generated canvas buttons 0 Answers

Issue with UI button positioning 1 Answer

Unity UI 4.6 Canvas Enable/Disable make Accessible 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges