1.实例化用Instantiate(要生成的物体,生成的位置,旋转角度)
2.检测鼠标左键并生成物体 If(Input.GetButtonDown(“Fire1”)){
Transform n = Instantiate(newobeject,transform.position,transform.rotation);
}
3.给物体加力 n.rigibody.AddForce(fwd*28000);
4.转换方向 Vector3代表xyz
Vector3 fwd=transform.TransformDirection(Vector3.forward);
Vector3.forward=>(0,0,1)
5.销毁物体 Destroy(gameObject,3.0);
6.多行注释/* */
7.对变量赋予物体, Inspector中直接拖
8.旋转物体 Input.GetKEy(KeyCode.Q){
transform.rotate(0,-25*Time.deltaTime,0,Space.Self);
}
Space.Self以自身轴旋转
25*Time.deltaTime
KeyCode.X不可用小写
9.走到地下问题,沿x轴旋转
Input.GetKEy(KeyCode.Z){
transform.rotate(-25*Time.deltaTime,0,0,Space.Self);
}
10.GUI Text(Unity 3d 5.0后变为UI-Text)
//Rotate in Y using Q and E
if(Input.GetKey(KeyCode.Q)){
transform.Rotate (0,-25*Time.deltaTime,0,Space.Self);
}
if(Input.GetKey(KeyCode.E)){
transform.Rotate (0,25*Time.deltaTime,0,Space.Self);
}
//Rotate in X using Z and C
if(Input.GetKey(KeyCode.Z)){
transform.Rotate (-25*Time.deltaTime,0,0,Space.Self);
}
if(Input.GetKey(KeyCode.C)){
transform.Rotate (25*Time.deltaTime,0,0,Space.Self);
}
//Raise or down camera
if (Input.GetKey (KeyCode.H)) {
transform.Translate (0,speed*Time.deltaTime,0);
}
if (Input.GetKey (KeyCode.N)) {
transform.Translate (0,-speed*Time.deltaTime,0);
}