Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
2
Question by LordSoth30 · Sep 23, 2013 at 09:53 AM · inputtextmouseclick

mouse input - displays object description on screen

Hello. Posted this on the forums but I think I should have done it here, I'm looking for a simple script that on Fire1 click, will display text on screen with the description of the object that has been clicked on. I'm very new to Unity and even more with scripting and languages, I have googled a lot and have a slight idea of what's going on behind some scripts, but not sure how to put this one together? Thank you for any help out there.

Comment
Add comment · 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 robertbu · Sep 23, 2013 at 11:32 PM 1
Share

As your question currently stands, it is not a good fit for Unity Answers. The primary problem is, "I'm looking for a simple script..." which can be interpreted to mean that you are looking for someone to write a script for you. Typically questions that ask for scripts are ignored or closed. Beyond that problem, your questions lacks the details necessary to do more than guess at the correct solution. $$anonymous$$y suggestion is for you to research the following:

How to detect a click on a game object:

  • On$$anonymous$$ouseDown()

  • Physics.Raycast()

Three ways to display text (and there are more):

  • GUI.Label

  • GUIText

  • 3D Text/Text$$anonymous$$esh

1 Reply

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

Answer by clunk47 · Sep 24, 2013 at 04:17 AM

I'd attach a script to each object and for example's sake, name it "Description". Here's a simple C# example on how you would go about using Raycast from the main camera using mousePosition, then using GetMouseButtonDown to bring up the string as a GUI Label. Also take a look at ScreenPointToRay.

 using UnityEngine;
 using System.Collections;
 
 public class Description : MonoBehaviour 
 {
     public string label = "Change this in the inspector for each object";
     Ray ray;
     RaycastHit hit;
     bool showLabel = false;
     
     void Update()
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, out hit, Mathf.Infinity) && Input.GetMouseButtonDown(0))
         {
             if(hit.collider == this.collider)
             {
                 showLabel = true;    
             }
             else
                 showLabel = false;
         }
     }
     
     void OnGUI()
     {
         if(showLabel)
             GUI.Label(new Rect(0, 0, Screen.width, 256), label);
     }
 }
 
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 clunk47 · Sep 25, 2013 at 04:41 AM 0
Share

@LordSoth30, you now have enough karma to upvote (thumbs up) comments and answers, you should do so for @robertbu's comment, as it is helpful advice. You can vote up my answer if you feel like it too lol

avatar image LordSoth30 · Sep 25, 2013 at 04:50 AM 1
Share

Thank you very much for the example, that's brilliant. I have read through the Unity wiki & script references, it was just putting it all together that I was having trouble with. Thank you once again!

avatar image clunk47 · Sep 25, 2013 at 04:52 AM 0
Share

Always happy to be of help, always feel welcome to come back if you need help with anything else :)

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

17 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

Related Questions

Differentiate left, right and both mouse inputs 0 Answers

Getting Camera on mouse click of a 3d text 1 Answer

Display user Input to a text UI element. 0 Answers

Disable mouse input and cursor in game 2 Answers

iPhoneKeyboard.Open cannot handle multiple entries. Is it a bug? 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