Skip to content

Instantly share code, notes, and snippets.

@arket
Last active January 3, 2016 02:29
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 arket/8395823 to your computer and use it in GitHub Desktop.
Save arket/8395823 to your computer and use it in GitHub Desktop.
Rayを飛ばしてスクリーン座標→ワールド座標へ
using UnityEngine;
using System.Collections;
public class ChangeScreenToWorldPoint : MonoBehaviour{
private RaycastHit mouse_hit;
public float limit_ray;
public Vector3 point_val;
void Start(){
if (limit_ray <= 0) limit_ray = 700.0f;
}
void Update(){
var ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out mouse_hit, limit_ray)){
Set_Position();
}
}
private void Set_Position(){
Debug.Log("hit:"+ mouse_hit.collider.gameObject.name);
// world座標
point_val = mouse_hit.point;
Debug.Log(point_val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment