这是我的剧本:
var ctexture : Texture2D;
function Update() {
var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
var pointVec=Camera.main.WorldToScreenPoint(hit.point);
GUI.Label(Rect(pointVec.x,pointVec.y,145,93),ctexture);
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
Debug.Log(hit.point);}}
我可以看到Debug.DrawRay光线,它就是我想要它的方式。问题是我无法看到GUI.Label的结果。分配了ctexture,Debug.Log打印出正确的信息。
提前致谢。
答案 0 :(得分:0)
将代码放在OnGUI()函数中:
var ctexture : Texture2D;
function OnGUI() {
var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
var pointVec=Camera.main.WorldToScreenPoint(hit.point);
GUI.Label(Rect(pointVec.x,pointVec.y,145,93),ctexture);
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
Debug.Log(hit.point);
}
}