4. 测量距离
Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetMouseButton(0))
{
if(Physics.Raycast(ray,out hit,1000))
{
if(cejupos1== Vector3.zero)
cejupos1 = hit.point;
cejupos2= hit.point;
lineRenderer.SetPosition(0,cejupos1);
lineRenderer.SetPosition(1,cejupos2);
lblceju.GetComponent<UILabel>().text="长度为:"+Vector3.Distance(cejupos1,cejupos2).ToString("#0.00")+"米";
}
}
else
{
cejupos1= Vector3.zero;
}
5. 复原场景
(1) 记录场景物体位置
GameObject[]diaoGuis=GameObject.FindGameObjectsWithTag("Cf_diaogui1");
StringBuilder bulid=new StringBuilder();
string oName=obj.transform.name;
bulid.Append(oName+",");
float Px=obj.transform.position.x;
bulid.Append(Px+",");
………………..
(2) 复原
string ss=System.Text.Encoding.UTF8.GetString(www.bytes);
string[] chas=ss.Split(new char[]{','});
while(true)
{
if(index>=chas.Length-1)
{
break;
}
stringasset="Prefab/chufang/"+chas[index];
floatx=float.Parse(chas[index+1]);
float y=float.Parse(chas[index+2]);
………………
GameObjectob= = (GameObject)Instantiate(Resources.Load(asset),pos,Quaternion.Euler(rot));
ob.transform.localScale= sca;
index+=10;
}