c# - RaycastHit issues with canvas? -


this script gives message on console if hit gameobject not in canvas. when mouse button released on button located inside canvas, script doesn't debug anything. how can fix this?

raycasthit hit;  void update ()  {     if(input.getmousebuttonup(0))     {         ray ray = camera.main.screenpointtoray(input.mouseposition);         //rayhit hit;         if(physics.raycast(ray, out hit))         {             // want             debug.log(hit.collider.gameobject.tag);         }     } } 

you can use ui object clicked.

    if (input.getmousebuttondown(0))     {         ray ray = camera.main.screenpointtoray(input.mouseposition);           if (eventsystem.current.ispointerovergameobject())         {             debug.log(eventsystem.current.currentselectedgameobject.getcomponent<text>().name);          } 

eventsystem.current.currentselectedgameobject.getcomponent().name

will return clicked object ,

eventsystem.current.ispointerovergameobject()

will check if ui object click or not.


Comments

Popular posts from this blog

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -

github - Git errors while pushing -

java - Generating a pre-signed PUT url for Amazon S3 with a maximum content-length -