Skip to content

Instantly share code, notes, and snippets.

@maco1028
Created July 10, 2017 22:17
Show Gist options
  • Save maco1028/85aa30f4d623dd4e4d0dabe9e9d03de0 to your computer and use it in GitHub Desktop.
Save maco1028/85aa30f4d623dd4e4d0dabe9e9d03de0 to your computer and use it in GitHub Desktop.
クリックしたオブジェクトの取得
// 左クリックしたオブジェクトを取得する関数(3D)
public GameObject getClickObject() {
GameObject result = null;
// 左クリックされた場所のオブジェクトを取得
if(Input.GetMouseButtonDown(0)) {
   Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
   RaycastHit hit = new RaycastHit();
   if (Physics.Raycast(ray, out hit)){
     result = hit.collider.gameObject;
   }
 }
 return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment