• 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
Question by JeevanjotSingh · Feb 03, 2015 at 09:53 AM · uibuttonscript.canvas

Unity UI 4.6 Canvas Enable/Disable make Accessible

Greetings . I need some help about canvas . My player needs to jump on pressing space or whatever i add to player . But in pause Button of my game i set If button click then enable the pause canvas with option like go to main menu and reload , now on resume button i set to enable = false the canvas but when i press 'space' after enabling and disabling it i got that some functions from pause canvas like reload or music on/off will execute instead of doing jump of player or any other function .

Comment
Krish-Vikram

People who like this

1 Show 1
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 JeevanjotSingh · Feb 03, 2015 at 10:45 AM 0
Share

I think with canvas i need to disable button script option . I think it works i am going to try this . But if there any other idea about this please post it.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Mmmpies · Feb 03, 2015 at 10:52 AM

Select the EventSystem in the hierarchy and un-tick send Navigation Events. That'll stop the keyboard interactions with the UI.

Comment
JeevanjotSingh

People who like this

1 Show 6 · 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 JeevanjotSingh · Feb 03, 2015 at 11:13 AM 0
Share

This sounds easy and effective . But how can i declare eventsystem variable . Is this Just 'Event' ?

avatar image HarshadK · Feb 03, 2015 at 11:27 AM 2
Share

The EventSystem is just a script component so it is like getting reference to a component attached to a gameobject. Like:

 EventSystem eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();

Now you can access the different properties of EventSystem script through this eventSystem variable.

One drawback of disabling EventSystem Send Navigation Event is that if there are any UI elements on your Gameplay Screen then they will stop receiving the input.

avatar image Mmmpies · Feb 03, 2015 at 11:34 AM 2
Share

Yes just as @HarshadK says, I've set a button to switch the EventSystem off and on via the UI itself. Probably fairly useless but it was just a test:

 using UnityEngine;
 using UnityEngine.EventSystems;
 using System.Collections;
 
 public class EventsOnOff : MonoBehaviour {
     
     private EventSystem eventSystem;
 
     void Start()
     {
         eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
     }
 
     public void ChangeEvents()
     {
         eventSystem.sendNavigationEvents = !eventSystem.sendNavigationEvents;
     }
 }
avatar image JeevanjotSingh · Feb 03, 2015 at 03:43 PM 0
Share

OK thanks guys , now i got it . First i need to gave the reference using event system Library file name,I was thinking first that it can be access by using .'`using UnityEngine.UI;`'I was totally wrong Event system has it's own defined file .

avatar image Mmmpies · Feb 03, 2015 at 03:47 PM 1
Share

Yep, I should really have pointed that bit out but for anyone else that needs this you need this adding in the using section:

 using UnityEngine.EventSystems;
Show more comments
avatar image

Answer by HarshadK · Feb 03, 2015 at 10:56 AM

It is not possible to provide provide exact solution without looking at your structure and code but looks like your scripts for handling the Canvas input contains code that looks for a keypress (like Space) and then reacts to it. So even when you disable your canvas your scripts for handling the canvas input are active and are taking that input.

One way is as you said to disable the scripts when you disable the canvas but to be on safer side you can also include a check in your input scripts for canvas that checks if the canvas is enabled before performing the action this way even if your script is not disabled (but your canvas is) it will not perform the action. And you can even disable the script once you found out that canvas is disabled but the script was not.

Comment
JeevanjotSingh

People who like this

1 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 JeevanjotSingh · Feb 03, 2015 at 11:10 AM 0
Share

That's also a great Idea! Awesome .

1st my input method checks if canvas enables then perform action , otherwise it doesn't perform . Now that's like programmer .

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image avatar image

Related Questions

UI button dosent show function 1 Answer

UI Buttons visible but not clickable when using two canvases. 3 Answers

Close the game after an amount of time by pressing a UI button 0 Answers

Problem with Button in ScrollView 0 Answers

I Have a Button in Canvas, i Click anywhere except the button and it gets clicked 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