Skip to content

Instantly share code, notes, and snippets.

@kankikuchi
Last active December 28, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kankikuchi/7510281 to your computer and use it in GitHub Desktop.
Save kankikuchi/7510281 to your computer and use it in GitHub Desktop.
Unity RaycastHit ジョイスティックにタッチ判定したかった
//タッチされている
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