Last active
December 28, 2015 13:49
-
-
Save kankikuchi/7510281 to your computer and use it in GitHub Desktop.
Unity RaycastHit ジョイスティックにタッチ判定したかった
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.touchCount > 0){ | |
//タッチされている指の数だけループ | |
foreach ( Touch touch in Input.touches ){ | |
Camera myCamera = GameObject.Find("Camera").camera; //カメラ | |
Ray ray = myCamera.ScreenPointToRay(touch.position); //光線 | |
RaycastHit hit; //光線が当たったときの情報 | |
//光線がなにかに当たった | |
if(Physics.Raycast(ray.origin,ray.direction,out hit,Mathf.Infinity)){ | |
Debug.Log("tag:" + hit.collider.tag); | |
//ジョイスティックにタッチ | |
if(hit.collider.tag == "joystick"){ | |
Debug.Log("joystick HIT!!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment