unity3d 基礎(chǔ)

Instantiate(a,b,c);函數(shù)

作用來創(chuàng)建一個物體
param a Transform 類型 需要創(chuàng)建的物體
param b Vector3 類型 創(chuàng)建物體擺放的位置
param c Quaternion類型 創(chuàng)建物體的擺放方向

也可以這樣創(chuàng)建

GameObject go= (GameObject)Instantiate(flyswordon);//創(chuàng)建預(yù)設(shè)
        go.transform .position =new Vector3 (1 ,2,3);//重新擺放預(yù)設(shè) 
            go.transform .Rotate (1,2,3 );//預(yù)設(shè)的旋轉(zhuǎn)角
RaycastHit info;
bool hit = Physics.Raycast (m_weapones.position, m_camTransform.TransformDirection (Vector3.forward), out info, 100,m_layer);
            if (hit) {
                Debug.Log (info.transform.tag);//碰撞到的物體的tag
                Instantiate (m_fx, info.point, info.transform.rotation);
            }

發(fā)射一個物理射線 起點、 方向、 距離、 可碰層
碰撞到的物體信息保存在info中


39AC8178-7717-4475-8F01-53E847048791.png

//獲取鼠標(biāo)在屏幕上移動量
float rh = Input.GetAxis("Mouse X");
float rv = Input.GetAxis("Mouse Y");

Transform.eulerAngles 歐拉角

transform.eulerAngles = new Vector3(10, 20, 0);

 print(transform.eulerAngles.x);//x軸旋轉(zhuǎn)角
 print(transform.eulerAngles.y);//Y軸旋轉(zhuǎn)角
 print(transform.eulerAngles.z);//z 軸旋轉(zhuǎn)角
//檢測點擊鍵盤上的Q鍵
if (Input.GetKey (KeyCode.Q)) {
    //向左旋轉(zhuǎn)
    transform.Rotate (0/*不沿x軸不旋轉(zhuǎn)*/, -25 * Time.deltaTime, 0/*不沿z軸不旋轉(zhuǎn)*/, Space.Self);
}
//繞著Y軸 逆時針旋轉(zhuǎn)
transform.Rotate (0/*不沿x軸不旋轉(zhuǎn)*/, -25 * Time.deltaTime, 0/*不沿z軸不旋轉(zhuǎn)*/, Space.Self);
//繞著Y軸 順時針旋轉(zhuǎn)
transform.Rotate (0/*不沿x軸不旋轉(zhuǎn)*/, 25 * Time.deltaTime, 0/*不沿z軸不旋轉(zhuǎn)*/, Space.Self);
 //檢測鍵盤輸入 x軸方向
float x = Input.GetAxis ("Horizontal") * Time.deltaTime * speed;
//檢測鍵盤輸入 z軸方向
float z = Input.GetAxis ("Vertical") * Time.deltaTime * speed;
//檢測鍵盤輸入 y軸方向
//float y = Input.GetAxis ("Vertical") * Time.deltaTime * speed;
transform.Translate (x, 0, z);
//使用UI 需要導(dǎo)入 using UnityEngine.UI;
numberOfFS++;
GameObject.Find("Canvas/FSText").GetComponent<Text>().text= "發(fā)射數(shù):"+numberOfFS;
//3.0秒之后銷毀 游戲?qū)ο?Destroy (gameObject, 3.0f); 

//打開一個場景
using UnityEngine.SceneManagement;
SceneManager.LoadScene("場景名稱");
Invoke 反射調(diào)用
SendMessage 通過尋找物體的所有腳本組件 中傳入的方法名稱  執(zhí)行傳入的方法
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容