Created
September 29, 2017 11:06
-
-
Save tblack-studio/a79554a3b7d75478cee8cc2ec64be4db to your computer and use it in GitHub Desktop.
Print Unity Game Object Name when clicking to them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Input.GetMouseButtonDown(0)) | |
{ | |
//empty RaycastHit object which raycast puts the hit details into | |
var hits = new RaycastHit[0]; | |
//ray shooting out of the camera from where the mouse is | |
var ray = Camera.allCameras[0].ScreenPointToRay(Input.mousePosition); | |
if ((hits = Physics.RaycastAll(ray)).Length > 0) | |
{ | |
//print out the name if the raycast hits something | |
foreach(RaycastHit hit in hits){ | |
Debug.Log(hit.collider.name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment