Unity3D learning notes Lesson 1: unity3d learning notes
Course 1:
1. The Unity class name must be consistent with the file name.
2. Setting the lecture property to public can be accessed in Unity
Public float speed;
// Use this for initialization
Void Start (){
}
// Update is called once per frame
Void Update (){
// Obtain the left and right direction keys (range:-1 to 1)
Float amtToMove = Input. GetAxis ("Horizontal") * speed;
// Use the matrix for translation
GameObject. transform. Translate (Vector3.right * amtToMove );
}
3. Camera: the output screen of the game is realized by the scene observed by the camera. The game scene is displayed on a 2D computer screen,
The two projection modes are Perspective Projection and orthogonal projection. By default, Unity is Perspective Projection. Perspective Projection has a sense of distance, while orthogonal projection has no sense of distance.
To develop an Unity2D game, you must change the projection method to orthogonal projection.
Three main parameters of Perspective Projection:
FieldofView (view ),
NearClipPlane (near view plane ),
FarClipPlane (far plane)
4. The GameObject contains the transform, camera attributes, GetComponet, AddComponent, and other methods.
5. Transform implements object position, rotation, and scaling
Position
Rotation
LocalScale
Translate Method
Rotate Method
6. Input. GetAxis () and Input. GetAxisRaw () Check direction keys
Detect move up/down
Input. GetAxis ("Vertical ")
Detect left and right movement
Input. GetAxis ("Horizontal ")
7. Time class
The time (in seconds) from the last deltaTime frame to the current frame.
8. Call sequence of three updates
MonoBehaviour. FixedUpdate ()
MonoBehaviour. Update ()
MonoBehaviour. LateUpdate ()
9. Move the square cyclically
Public class Player: MonoBehaviour {
Public float playerSpeed;
// Use this for initialization
Void Start (){
}
// Update is called once per frame
Void Update (){
Debug. Log ("Update ");
Var moveto = Input. GetAxis ("Horizontal") * Time. deltaTime * playerSpeed;
GameObject. transform. Translate (Vector3.right * moveto );
If (transform. position. x> 9.15 ){
Transform. position = new Vector3 (-9.15f, transform. position. y );
}
If (transform. position. x <-9.15 ){
Transform. position = new Vector3 (9.15f, transform. position. y );
}
}
Void LateUpdate (){
Debug. Log ("LateUpdate ");
}
Void FixedUpdate (){
Debug. Log ("FixedUpdate ");
}
}
9. Create a button and respond to the button operation
Void OnGUI (){
If (GUI. Button (new Rect (0, 0,100, 50), "Play ")){
}
Else if (GUI. Button (new Rect (0, 60,100, 50), "Pause ")){
}
Else if (GUI. Button (new Rect (0,120,100, 50), "Stop ")){
}
}