Question by
arash-k · Oct 04, 2015 at 12:19 PM ·
c#gameobjectraycast.mb
how to get name of game object with position by raycast
i used OnMouseDown() but it's so simple and not useful :
void OnMouseDown()
{
Debug.Log("The " + this.GameObject.name + " was clicked");
}
Comment
Answer by Suddoha · Oct 04, 2015 at 12:44 PM
Just gameObject with a lowercase:
void OnMouseDown()
{
Debug.Log("The " + gameObject.name + " was clicked");
}
Note that OnMouseDown already uses a raycast internally, so you don't need an extra raycast.
(I also commented your other question in regards to using the name of the object that you were chaching there.)