Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Jalah_LLC · Apr 23, 2016 at 03:43 AM · uieventsystemboolevent triggeringclick objects

How to only click on certain objects/buttons and null the rest please help!!

Hey everyone, I was wondering if anyone could help me with this. I have been trying to figure it out for days. I would really appreciate the help. I am trying to figure out how to null/not have click activated when I click on the pop up UIs. The pictures as shown:

alt text

I have a script in which I am able to click on the triangles. The blue space is nulled out/does not do anything. The code I am using is:

 public class ClickObject : MonoBehaviour {
 [SerializeField]
 private GameObject NextLevelUI;
 [SerializeField]
 private GameObject TryAgainUI;
 
 
     void  Update (){
 
 
     
         RaycastHit2D hit;
 
 
 
 
         if(Input.GetMouseButtonDown(0)){
 
         
             hit=Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition) , Vector2.zero);
             if (hit.collider != null){
                 TryAgainUI.SetActive(true);
                 if(hit.collider.GetComponent<MoveSample>()!= null && hit.transform.gameObject.tag=="TriangleP"){
                     NextLevelUI.SetActive(true);
                     TryAgainUI.SetActive (false);{
                         Debug.Log("SUCCESS");
 

When I click on the right object that has the movesample script attached, It directs to the correct pop up UI. When I clicked on the wrong object, it goes to the incorrect pop up. Here is an example of the correct UI:

alt text

What I want to do is have the ability to ONLY click on the button and nothing else. The triangles and background all null/unable to do anything. I have been looking into bools, event systems, if else statements, but not sure how to do this. If anyone could help I would GREATLY appreciate it. Thank you.

capture99k.png (10.2 kB)
sdsf.png (48.8 kB)
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
0

Answer by FWCorey · Apr 23, 2016 at 04:07 AM

Create layers for the objects you want your raycasts to hit and when you perform your:

hit=Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition) , Vector2.zero);
use instead:
hit=Physics2D.Raycast(
                     Camera.main.ScreenToWorldPoint(Input.mousePosition),
                     Vector2.zero,
                     LayerMask.GetMask("MyValidLayerName"));

You can find info on using Layer tags here - Tags and Layers

Comment
Add comment · Show 3 · 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 Jalah_LLC · Apr 23, 2016 at 04:36 AM 0
Share

@FWCorey would this solve the issue? I typed in exactly what you put under the "use ins$$anonymous$$d", replacing the $$anonymous$$yValidLayerName with "UI", as that are with my pop ups. It does not seem to work, I am still able to click on the triangles which register the incorrect pop up UI while being in the correct pop up UI. Am I missing something or not quite understanding? Anymore help or understanding would be greatly appreciated!!

avatar image FWCorey · Apr 23, 2016 at 09:01 PM 0
Share

UI is one of Unity's built-in layers. You need to create a new layer of your own and have only the GameObjects you want clickable on it.

avatar image Jalah_LLC FWCorey · Apr 24, 2016 at 06:46 PM 0
Share

@FWCorey thanks for replying. I did create my own UI layer, applied it to the pop up UI and had that code above, but I am still able to click on the triangles. Am I missing something? Any help would be greatly appreciated. Thank you.

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

72 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 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 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 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

Selectable/Button not being selected 0 Answers

Unity UI Events not working for Canvas objects 1 Answer

How to check what UI type is currently in focus 1 Answer

How do I NOT play a sound on the first selected button. 2 Answers

Input Field Not Interactible 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