Created
July 10, 2017 22:17
-
-
Save maco1028/85aa30f4d623dd4e4d0dabe9e9d03de0 to your computer and use it in GitHub Desktop.
クリックしたオブジェクトの取得
This file contains hidden or 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
// 左クリックしたオブジェクトを取得する関数(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