• 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
0
Question by GiulioPerosino · Nov 05, 2013 at 07:14 PM · mouseclickinteraction

Display a window with a message when the game object is clicked

Hi all.. I'm new to Unity and scripting. Can anyone help me with a simple thing? I can't find this thread on the internet so I'm asking here:

How to display a window with a message when I click the mouse button on the object and when I'm quite close to it? And I would also be able to display a GUI icon like "Click the left mouse button to interact".

I've posted two example images in order to be more clear with my question. ![alt text][1]

![alt text][2]

Thank you very much guys!! [1]: /storage/temp/17473-esempio+per+museo+1.jpg [2]: /storage/temp/17475-esempio+per+museo+2.jpg

esempio per museo 1.jpg (300.5 kB)
esempio per museo 2.jpg (357.4 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 TimBorquez · Nov 05, 2013 at 10:21 PM

you're gonna need to look into raycasting, a very easy way would be to make a script to put on the object itself with the built in onmousedown function

on mouse down

on gui

and in the onmousedown function toggle a boolean variable on/off

then in the ongui function show the picture depending on the variable,

so like a script like this on the object you want to click:

 private var GUIToggle = false;
 
 function OnMouseDown () {
     GUIToggle = !GUIToggle;   //switches to opposite boolean
 }
 
 function OnGUI () {
 
      if(GUIToggle == true)
      {
           //here you put the code for a picture
           //(using a gui label or whatever you want)
      }
 }


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 TimBorquez · Nov 05, 2013 at 10:22 PM 0
Share

also i didnt test that code but i dont think i messed up anywhere

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

16 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

Related Questions

mouse click on objects 1 Answer

first person controller with interaction 2 Answers

Animating a chest to open/close for unity 1 Answer

characters interaction 1 Answer

How would i display text and get rid of it 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