void Start();//The game starts to execute once
void Updata();//Called every frame
void Reset();//Triggered when attaching or unattaching
Time class
.delta//The duration of each frame
.fixedTime//The time from the start of the game to the present
.frameCount//How many frames have been run since the beginning of the game
.timeScale/*The deltaTime will be divided by this value, set to 0 to pause the game
You can also set different values to achieve the scaling of the set motion rate
*/
GameObject class
//1. Create a game object (for creating an empty game object)
GameObject go=new GameObject("cube");
//2. Create a game object based on prefab or another game object
GameObject.Instantiate(prefab);
//3. Create the base object
GameObject.CreatePrimitive(PrimitiveType.cube);
//Add components to the game object
.AddComponent<component name>();//You can also add your own scripts
.activeInHierarchy//Get whether the game object is active (read-only)
.SetActive(false);//Set the active state of the game object
.tag//Get the Tag tag value of the game object (for the classification of game objects)
//Get the component on the game object
.GetComponent<component name>();
//find the game object
Find(game object name);//Static method
FindGameObjectsWithTag(tag name)//Static method, negative number search, returns an array of GameObjects
//Broadcast message (look for this method on the game object and its children to execute)
.BordcastMessage(方法名,null,SendMessageOptions.DontRequireReciver);/*
SendMessageOptions.DontRequireReciver means that no error will be reported even if there is no receiver
*/
//Send information for a game object
.SendMessage(方法名,null,SendMessageOptions.DontRequireReciver);
//For a game object and all its parent objects
.SendMessageUpwards(方法名,null,SendMessageOptions.DontRequireReciver);
Object class
.name //Get the name
Destroy(object);//Static method, destroy the object
DontDestroyOnLoad(object);//Do not destroy this object when loading a new scene
FindObjectOfType<light>();//Static method to find a certain type of component (the first one) in the current scene, not to find inactive ones
// After adding this feature to the class, the class will also run in editor mode
[ExecuteInEditMode]
MoonBehaviour类
.enable//Set the activation state of the component
.name
.tag
.gameObject
.transform
Invoke(method name, seconds);//Invoke the method after x seconds
IsInvoking("Attack");//Determine whether the method is in the called state
InvokeRepeating(method name, call after a few seconds, call time interval);//Loop call
CancelInvoke();//Cancel all Invokes without giving parameters, and cancel the specified Invokes with the specified parameters
Coroutines//Coroutine method (will not block the thread, do not wait for return), the coroutine method should add IEnumerator before the method
//1. The return value is IEnumerator
//2. Use yieldreturn null/0 when returning;
//3. Use StartCoroutine(method()) when calling the coroutine method;
yield return new WaitForSeconds();//In the coroutine, wait for x seconds
StopCoroutine(coroutine method name)//Stop the coroutine (how to open and close)
StopCoroutine(IEnumerator object)//Stop the coroutine
//Open with method name, close with method name, open with method name, close with IEnumerator
//Mouse related functions
// math class
Mathf
Abs();//absolute value
Clamp();//Limit the return value, in min and max, it will return itself, if it is too small, it will return to min, and if it is too large, it will return to max
DeltaAngle();//Calculate the minimum difference between 2 angles (angle)
Cell();//Round up
Floor();//Round down
Sqrt();//Get the square root
ClosestPowerOfTwo(x);//Get x away from 2 4 8 16 32. . most recent value
//t generally uses Time.deltaTime, if t is negative, it is far away, and if t is positive, it is close
Lerp(a,b,t);//Interpolation operation, t=0 takes a, t=1 takes b, t=0.5 takes the middle (value in proportion), first fast and then slow
LerpAgle();//Interpolation, 0-360 degrees
MoveTowards(a,b,t);//Uniform interpolation, 1m/s
PingPong(t,length);//(Back and forth movement) The minimum value is 0, the default t=0, if t increases and is within the range of length, t increases normally, if t increases beyond length, it decreases instead
Input//input stream
Getkey();//Get continuous keyboard events
GetKeyDown();//Get down the keyboard event
GetKeyUp();//Get up the keyboard event
GetMouseButton(x);//Get the mouse button pressed continuously, x=0,1,2 means left button, right button, middle button
GetMouseButtonDown();//The mouse button is pressed
GetMouseButtonUp();//Mouse button up
GetButton();//Monitor virtual buttons
GetButtonDown();
GetButtonUp();
GetTouch();//Touch monitoring, easyTouch plugin is used to monitor touch gestures, etc.
.anyKey;//Monitor any key pressed (mouse and keyboard)
.mousePosition//Get the position of the mouse on the screen, in pixels
Vector2 structure
Vector2 a=new Vector2(2,3);
a.magnitude//Get the length of a
a.sqrMagnitude//Get the x square + y square of a
a.normalized//Get a unit vector, keep the direction unchanged, and the length becomes 1
Angle(vector2 x, Vector2 y);//Get the angle between 2 vectors
Distance(vector2 x, Vector2 y);//Get the length between 2 vectors
Vector3 structure
Project(Vector3 vector, Vector3 onNormal);//Get the projection of a vector on another vector
Reflect();//Get the reflection vector
Slerp();//Angle interpolation (for steering)
Random class
Ranage();//Static method to get a random number
InitState(int i);//Set the random number seed, the seed is the same, the generated random number sequence is the same
rotation();//Get a quaternion
insideUnitCircle();//Generate random points in a circle with radius 1 near a point
insideUnitSphere();//Random Vector3 points in a sphere with a radius of 1
Quaternion quaternion structure
Euler(vector3 x);//Convert an Euler angle to a quaternion
LookRotation();//Let a game object face a Vector3 vector
Rigdbody rigid body component class
Inherit from component class
.position//Control position (move once)
MovePosition(Vector3 x);//Interpolation continues to move
//Whether it is moving the position or modifying the rotation, the rigid body is more efficient
Motion control by applying force via AddForce
AddForce(Vector3 x, size of force);
Camera class
The camera class is often used for ray detection, getting the screen position, rendering
AppLication class
File operations, platform detection, packaging settings
Toggle loading scene
SceneManger类
Need to introduce namespace UnityEngine.SceneMangement
LoadScene(); load scene