今天又和群里的高手谈论了下这个问题,carlos.yang和airdamper给了我很大的帮助,给我提出了用射线检测法的可行性和优点。射线检测 射线碰到碰撞体后会返回一个检测信息 包含碰到的物体的名字之类,就是返回一个引用型的变量,这个变量就可以当做你射到那个物体来用。1、使用Camera.ScreenPointToRay得到一条射线,2、然后使用射线检测函数Physics.Raycast,然后会得到RaycastHit 信息,根据信息可以判断你到底点中了什么。Camera.ViewportPointToRay
也行不过这个是基于视口的,超出了你的程序框框就无效。不过这个我没试,由于时间仓促,等有空再试吧。
修改后:
View
Code
Code
1 var gui : GUITexture; 2 var find : GUITexture; 3 //var GameObjectName; 4 function Awake(){ 5 find=GameObject.Find("guiTexture").GetComponent(GUITexture); 6 find.enabled=false; 7 } 8 9 function OnMouseDown() 10 { 11 //find=GameObject.Find("guiTexture").GetComponent(GUITexture); 12 find.enabled=true; 13 Debug.Log(gameObject.name); 14 www(gameObject.name); 15 } 16 17 function www(Cubename){ 18 // Store the original pixel inset 19 // and modify it from there. 20 var originalPixelRect = gui.pixelInset; 21 22 // Update the progress bar by scaling the gui texture 23 // until we reach the end 24 var stream=new WWW(""+Cubename+".unity3d"); 25 while (!stream.isDone) 26 { 27 gui.pixelInset.xMax = originalPixelRect.xMin 28 + stream.progress * originalPixelRect.width; 29 yield; 30 } 31 // Update it one last time before loading 32 gui.pixelInset.xMax = originalPixelRect.xMax; 33 stream.LoadUnityWeb(); 34 } 35 @script RequireComponent (GUITexture)
再次感谢群里的carlos.yang对我的指点。