知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
Unity_常用的一些方法記錄
發(fā)表時(shí)間:2020-10-18
發(fā)布人:葵宇科技
瀏覽次數(shù):74
Unity_常用的一些方法記錄
- 1.通過(guò)物體名字查找游戲物體
- 2.查找對(duì)象中的組件
- 3.調(diào)用其他對(duì)象下組件中的方法
- 4.打印數(shù)據(jù)
- 5.獲得/設(shè)置物體的locaiton、rotation、scale
- 6.兩點(diǎn)間的距離
- 7.unity與web間(webgl/webplayer)的傳輸:傳出、傳入
- 8.lerp插值運(yùn)算
- 9.修改物體的材質(zhì)
- 10.將變量暴露給編輯器,方便在編輯器中手動(dòng)修改
1.通過(guò)物體名字查找游戲物體
GameObject.Find(“Cube”);//查找名為Cube的游戲物體
GameObject.Find(“GameObject/Canvas/Text”);//可以指定路徑位置
2.查找對(duì)象中的組件
GameObject.GetComponent<組件名稱>();
3.調(diào)用其他對(duì)象下組件中的方法
GameObject.Find(“腳本所在的物體的名字”).SendMessage(“函數(shù)名”); //能調(diào)用public和private類型函數(shù)
GameObject.Find(“腳本所在的物體的名字”).GetComponent<腳本名>().函數(shù)名(); //只能調(diào)用public類型函數(shù)
4.打印數(shù)據(jù)
Debug.Log(“打印內(nèi)容”);
5.獲得/設(shè)置物體的locaiton、rotation、scale
- 位置:
Vector3 player_postion = this.transform.position;// 獲取Player變量指定的對(duì)象的(X,Y,Z)
// 獲取X,Y,Z值
float x = player_postion.x;
float y = player_postion.y;
float z = player_postion.z;
//設(shè)置位置
// 1.直接賦值
this.transform.position = player_postion;
// 2.在某GameObject的基礎(chǔ)上加
this.transform.position = new Vector3(player_postion.x, player_postion.y + 7.79F, player_postion.z - 15);
//或者是
this.transform.position = player_postion + new Vector3(0, 7.79F, -15);
- 旋轉(zhuǎn):
this.transform.eulerAngles //獲得旋轉(zhuǎn)
this.transform.localEulerAngles=new Vector3(float Pitch,float Yaw,float Roll); //設(shè)置絕對(duì)旋轉(zhuǎn)
- 縮放:
this.transform.localScale //獲得縮放
this.transform.localScale = new Vector3(x, y,z);//修改縮放
6.兩點(diǎn)間的距離
Vector3.Distance(a,b) //a和b是兩個(gè)點(diǎn)的坐標(biāo)position值
7.unity與web間(webgl/webplayer)的傳輸:傳出、傳入
- 傳出:
在unity中寫如下調(diào)用語(yǔ)句:
Application.ExternalCall( “SayHello”, “The game says hello!” );
在html中定義函數(shù)如下
function SayHello(args){
alert(args);
}
- 傳入:
在unity中定義函數(shù)如下,并將帶有FunctionName函數(shù)的腳本綁定到Main Camera中
HTML中寫:
SendMessage(“Main Camera”, “FunctionName”, 參數(shù));//向unity中的Main Camera對(duì)象下的FunctionName函數(shù)傳入?yún)?shù)
SendMessage方法只能傳遞一個(gè)參數(shù),不然會(huì)報(bào)錯(cuò),所以通常傳遞多個(gè)參數(shù)的時(shí)候,將數(shù)據(jù)組成json數(shù)據(jù),以string的形式傳入
8.lerp插值運(yùn)算
從A點(diǎn)過(guò)渡到B點(diǎn)
Transform.position = Vector3.Lerp(A點(diǎn)坐標(biāo), B點(diǎn)坐標(biāo), alpha);//alpha過(guò)渡值:0時(shí)取A,1時(shí)取B,將alpha從0過(guò)渡到1即可
9.修改物體的材質(zhì)
this.GetComponent().material = 新材質(zhì);
10.將變量暴露給編輯器,方便在編輯器中手動(dòng)修改
C#中將變量設(shè)置為公開:
public flaot f;
public Vector3 position;
相關(guān)案例查看更多
相關(guān)閱讀
- 汽車報(bào)廢回收管理系統(tǒng)
- 昆明小程序設(shè)計(jì)
- 云南建站公司
- 小程序開發(fā)排名前十名
- 昆明做網(wǎng)站建設(shè)的公司排名
- 云南網(wǎng)站建設(shè)優(yōu)化
- 網(wǎng)站上首頁(yè)
- 網(wǎng)站建設(shè)方法
- 汽車拆解系統(tǒng)
- 云南網(wǎng)站建設(shè)首選
- 云南小程序開發(fā)
- 網(wǎng)站制作哪家好
- 云南網(wǎng)站建設(shè)百度
- 云南網(wǎng)站建設(shè)服務(wù)
- 網(wǎng)站建設(shè)招商
- 百度排名
- 開發(fā)框架
- 云南小程序開發(fā)公司
- 網(wǎng)站建設(shè)首頁(yè)
- 云南小程序被騙
- 云南網(wǎng)站建設(shè)電話
- 網(wǎng)站排名
- 云南網(wǎng)站維護(hù)
- 云南網(wǎng)站建設(shè)公司哪家好
- web前端
- 昆明做網(wǎng)站
- 昆明軟件公司
- 小程序生成海報(bào)
- 開發(fā)微信小程序
- 區(qū)塊鏈