• 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 drodrii · Nov 29, 2014 at 08:16 PM · cameraguiinputbuttonscreen

Clicking Trigger

Hello everyone, thanks for your time!

I want the user to click the screen to get a message.(In t$$anonymous$$s case, where the user clicked). Now there are some buttons on the screen but I don't want the message to appear if the user clicked those buttons.

Is there a way to manage around t$$anonymous$$s problem?(so when the user clicks the buttons, there's no message popUp?)

Here's what Im using for the code:

     if(Input.GetMouseButtonDown(0))
         {
 
             Debug.Log("Clicking");
             dist = transform.position.z - _camera.transform.position.z;
             userInputPosition = (new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist));
 
             userInputPosition = _camera.ScreenToWorldPoint (userInputPosition);
 
             Message ();
             //Send PopUp();
 
 
 
         }

Comment

People who like this

0 Show 5
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 Avash · Nov 29, 2014 at 08:39 PM 0
Share

Why don't you use the new unity ui or are you using 3d mesh text? Anyway you should post rest of your code. What is in the Message()? Is "PopUp" text?

avatar image drodrii · Nov 29, 2014 at 08:44 PM 0
Share

@Avash Im using New because The "world" moves. The idea is that the user clicks the "world" and gives you a debug of where you clicked(in the "world"). As the script is attached to a camera we have to convert from camera to "world" point....

Message() does nothing really, just gives a Debug that says "You should add the code of a popUp"

But that debug message gets called even when I clicked a button. I don't want the events to be called if Im clicking GUI. Just the "world" screen.

Thanks for your time.

avatar image drodrii · Nov 29, 2014 at 08:46 PM 0
Share

@Avash

So in quick words, I want to ignore the script when Im clicking GUI.

avatar image Avash · Nov 29, 2014 at 08:50 PM 0
Share

What do you mean by "New"? Do you mean Unity 4.6 ui?

avatar image drodrii · Nov 29, 2014 at 08:56 PM 0
Share

@Avash Nevermind I thought you meant the (new vector3... Im just downloading Unity 4.6. So, what exactly do you mean by using the new. Won't it be just the same? or what exactly should I be looking at with the new Unity?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Avash · Nov 29, 2014 at 09:03 PM

You should probaly use raycast and check is mouse pointing to the right collider (trigger) and mouse button down at the same time.

 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 Raycast$$anonymous$$t $$anonymous$$t;
 Physics.Raycast (ray, $$anonymous$$t, 5);
 if(Input.GetMouseButtonDown(0) && $$anonymous$$t.collider.name == "YourGameObjectName"){
 Message ();
 }

EDIT: http://answers.unity3d.com/questions/777818/46-ui-calling-function-on-button-click-via-script.html

Comment
Joe_User

People who like this

1 Show 2 · 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 drodrii · Nov 29, 2014 at 09:43 PM 0
Share

@Avash Is it possible to do something like:

!hit.collider.name == "GUI" ??

The problem I see in this is that If I add more objects(Which I was thinking about..) I must do a check for each object in the name area...

So I guess its easier to exclude GUI, but I don't know if GUI has colliders...

avatar image Avash · Nov 30, 2014 at 11:46 AM 0
Share

Make buttons in the editor, assign them in script and use onClick.

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

27 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

Related Questions

Can the Camera be Positioned on the Game Screen through code? 0 Answers

Android Button Screen 1 Answer

Attach image to button 1 Answer

How do I make a "move pad" on the screen? (Mobile) 1 Answer

Making a button's placement independent of resolution 1 Answer


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