2
\$\begingroup\$

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

enter image description here

and

enter image description here

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):

Please help. Thank you!

Update:

i already got the script that hold movement and attack logic like the image that shown below sir @Korchkidu:

enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can add colliders to your objects. Then, each time the mouse "enters" the collider, it calls void OnMouseEnter(). When the mouse exits, it calls void OnMouseExit(). So just create a script like:

using UnityEngine;
using System.Collections;

public class TestHover : MonoBehaviour 
{
    // Use this for initialization
    void Start () 
    {

    }

    // Update is called once per frame
    void Update () 
    {

    }

    void OnMouseEnter()
    {
        Debug.Log("Entering");
    }

    void OnMouseExit()
    {
        Debug.Log("Exiting");
    }
}

Finally, drag and drop this script onto your objects and it should work.

\$\endgroup\$
2
  • \$\begingroup\$ how do i add the script to the collider sir? i already create a sphere, and that sphere got sphere collider.. How do i attach another script to that collider? because the object that i create (sphere), already got 1 script that hold movement and attack logic in there. i already updated the question regarding the collider, please refer to it sir. thanks \$\endgroup\$
    – Kaoru
    Nov 28, 2013 at 16:42
  • \$\begingroup\$ drag and drop the script onto your asset. \$\endgroup\$
    – Korchkidu
    Nov 28, 2013 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .