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
0
Question by Fuhans · Nov 27, 2013 at 05:39 PM · c#turnbased

Show the tooltip when mouse over at the object

Hi, i wanted to show the tooltip like this when the mouse over at the object, here is the example image:

alt text

i already tried this below code, but the message on the debug.log didn't showed up when i am hovering my mouse to the object, the object i give the name same like this:

 void Update() 
 {
 
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
     RaycastHit hit;
 
     if (Physics.Raycast(ray,out hit) && hit.collider.gameObject.name == "Yify")
     {
 
         Debug.Log("Yify");
 
     }
 
 }

And here is my object (i use List to multiple the objects and each object i gave the name), (The object's name "Yify" is on the right side, dark green color):

alt text

Please help. Thank you.

capture.png (19.5 kB)
capture3.png (32.5 kB)
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 yatagarasu · Nov 29, 2013 at 11:17 AM 0
Share

Does your object have a collider?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by markmmiller · Nov 27, 2013 at 06:35 PM

Tried the code that you've written and seems fine to me. Are you sure your tag is correct on the object within the scene?

Also depending on what you are doing I would recommend changing your code over to this format here if you are going to check multiple tags, this way you won't send out multiple rays for each check in a single frame.

 if (Physics.Raycast(ray,out hit))
 {
     if(hit.collider.gameObject.name == "staticObject")
     {
         // Display tool tip
         Debug.Log("staticObject");    
     }
 }

I would also not recommend using just the tags to decide what is displayed. You could instead attach a class to the object (TooltipInfo) and have a check to see if that class is attached to that object, then have a general DisplayTooltip() function that will display all associated information related to that Tooltip object.

Comment
Add comment · Show 11 · 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 Fuhans · Nov 28, 2013 at 03:06 PM 0
Share

yes sir, i looked at it and it is the correct object, but when i hover the mouse to that object, nothing happen and the debug log also not come out

avatar image markmmiller · Nov 28, 2013 at 03:46 PM 0
Share

It's difficult to say without seeing the rest of your project. I can confirm that the should work. Have you checked the case of the tag? Have you ensured the script is attached to something within the scene?

If you could try the following code to ensure the ray is being cast correctly. It will also tell you the name and tag of whatever objects it collides with.

 if (Physics.Raycast(ray,out hit))
 {
     Debug.Log("Hit detected with, Name : " + hit.collider.gameObject.name + ", Tag : " + hit.collider.gameObject.tag);    
  
 }
avatar image Fuhans · Nov 29, 2013 at 10:46 AM 0
Share

Yes sir, the raycast working properly, but the if statement after the raycast, is not executed! Here is the screenshot when i tried your last code (just a raycast, without hit.collider.gameObject.name), but when i hovering the mouse to the object, the Debug.Log still display "Tile(clone)"

alt text

Here is the screenshot when i tried "hit.collider.gameObject.name == Yify" (nothing happen when i hovering the mouse to the object): alt text

and here is the code that i set the name of the object (red one object) to the "Yify":

 void GenerateObjects()
     {
         UserPlayer player;
         //AIPlayer aiplayer;
 
         //First turn
         player = ((GameObject)Instantiate(UserPlayerPrefab, new Vector3((mapSize - 2) - $$anonymous$$athf.Floor(mapSize / 2), 1.5f, -(mapSize - 1) + $$anonymous$$athf.Floor(mapSize / 2)), Quaternion.Euler(new Vector3()))).GetComponent<UserPlayer>();
         player.gridPosition = new Vector2(mapSize - 2, mapSize - 1);
         player.playerName = "Yify";
 
         players.Add(player);


Thank you sir

avatar image yatagarasu · Nov 29, 2013 at 11:19 AM 0
Share

Don't see where you set objects name. player.name = "Yify"; anywhere?

avatar image ramjigeddam · Nov 29, 2013 at 11:21 AM 0
Share

The name 'List' does not denote a valid type ('not found')?

These comes in Java Script

Please help me any one

Show more comments
avatar image
1

Answer by belvita · Nov 29, 2013 at 04:02 PM

I think it is because u r using .name .it usually doesnt work properly so try this it will work

void Update() {

 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
 RaycastHit hit;
 
 if (Physics.Raycast(ray,out hit) 
   {

        if(hit.collider.gameObject.tag== "Your game object tag name")

      
          {
 
             Debug.Log("Yify");
 
          }
   }

}

Comment
Add comment · 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
1

Answer by Moor · Nov 30, 2013 at 04:45 AM

   var TText:String="";
 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     var hit : RaycastHit;
     if (Physics.Raycast (ray, hit, 1000)) {
        if(hit.collider.name=="Yify")
         TText=hit.collider.name;
        else TText="";
       }
 
 function OnGUI(){//for tooltip
 if(TText!="")//GUIStyle to decorate the label
   GUI.Label (Rect (Input.mousePosition.x, Screen.height-Input.mousePosition.y, 100, 20), TText);
 }
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 Moor · Nov 30, 2013 at 04:48 AM 1
Share

better tag all the element, which u want for tooltip and refer check with tagg like

if(hit.collider.tag=="TTTag")//Line 6

avatar image Fuhans · Nov 30, 2013 at 08:49 AM 0
Share

Cannot sir, the TText always null, the program not executed on TText = hit.collider.name

avatar image belvita · Nov 30, 2013 at 08:56 AM 0
Share

use this

if(hit.collider.gameObject.tag== "Your game object tag name")

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

21 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Why is Unity crashing every time I press play in the editor after switching scenes? 0 Answers

invalid arguements for UIToolkit C# 1 Answer

Set the position of GUIBox 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