Last active
January 3, 2016 02:29
-
-
Save arket/8395823 to your computer and use it in GitHub Desktop.
Rayを飛ばしてスクリーン座標→ワールド座標へ
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
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