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
//獲取鼠標在屏幕上移動量
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í)行傳入的方法