When I hover over an UI object (Image) I want to get its name. How do I do it?
This code doesn’t seem to work:
function FixedUpdate () {
var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if(hit.collider != null)
{
infoTD.text = hit.collider.gameObject.name.ToString();
}
}
PGJ1
3
Also, is your GUI component located in the scene, otherwise it isn’t in world coordinates.
What you’re trying to accomplish is much easier to do if you use add an Event Trigger to your Image.
1 Like
http://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
pointer enter and exit events
(they really need some better content in those docs though
)