当前位置:网站首页>Basic knowledge points
Basic knowledge points
2022-07-05 04:54:00 【yaohuiyaoo】
One .CS Basic knowledge
1. Color gradient
Color.Lerp( picture .color,Color.clear,Time.deltaTime Speed );
Color.clear: Clear the color
2. Script sequence adjustment
Edit->Prodect Setting->Script Execution Order
3. Character movement
float h = Input.GetAxis(“Horizontal”) * Time.deltaTime * speed;
float v = Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
Vector3 dis=transfrom.righth+transfrom.forward*v;
4. Angle of view rotation
4.1 Method 1
//1. role y Variation of Spin = Self rotating y angle + mouse x Axis change Speed ;
float rotationY=transfrom.localEulerAngles.y+Input.GetAxis(“Mouse X”)20;
//2. role x Variation of Spin = Self rotating x angle + mouse y Axis change Speed ;
float rotationX=transfrom.localEulerAngles.x+Input.GetAxis(“Mouse Y”)15;
//3. Limit x: role x Rotation Angle =Mathf.Clamp( Oneself x The angle of , The minimum Angle , Maximum Angle );
rotationX=Mathf.Clamp(rotationX,-45,45);
//4. Change the setting from its own angle :
tranfrom.localEulerAngles=new Vector3(-rotationX,rotationY,0);
Be careful : Move the mouse up ,x Counter clockwise rotation
4.2 Method 2
Vector cameraRotate;
Float x=Input.GetAxis(“Mouse X”);
Float y=input.getAxis(“Mouse Y”);
cameraRotate.x-=y10;
cameraRotate.y-=x10;
cameraRotate.x=Mathf.Clamp(CameraRotate.x,-45,45);
cameraROtate.y=Mathf.Clamp(CameraRotate.y,-45,45);
4.3 Freeze rigid bodies
GetCompont().freezeRotation=true;
5. Shooting
Raycast hit;
//Physics.Raycast( Player coordinates , The player faces the direction ,out hit,100);
Physics.Raycast(pos.postion,pos.forward,out hit,100);
// Clone sound
6. Add audio
AudioClip climp;
climp=Resources.Load( route );
AudioSource.PlayClipAtPoint(climp, Play coordinates );
7. Bullet hole
GameObject helogo=Instantiate(hole,hit.point,Quaternion.identity);
//hit.normarl Is the normal of the ray , Vertical ray
// Towards the direction of the difference between the ray and the normal
Helogo.transfrom.LookAt(hit.point-hit.normal);
Hologo.transfrom.Translate(Vector3.back0.01f);
8. Constant :const
9. Screen center
New vector3 (Screen.width * 0.5f, Screen.height * 0.5f, 0);
10. The enemy is facing the player
Tanssfrom.LookAt(player.position);
Two . Panda war
1. The map cycle repeats
// Cyclic value t, Make it never greater than length, Not less than 0.
//Time.time To calculate the time from the beginning of the game
// Constantly approaching 15, exceed 15 Ab initio calculation
Float a= Mathf.repeat(Time.time5,15);
Transfrom.position=pos.postion+a*vecter3.back;
3、 ... and .12.11
trigger
Triggers , Just check... In the collider assembly in the inspector Is Trigger Property selection box .
Triggers can penetrate , So remove the gravity
// The frame that triggered the contact is called
void OnTriggerEnter(Collider other) {
Debug.Log(“enter”);
Debug.Log(other.gameObject.name);
}
// Every frame that triggers the contact is called
void OnTriggerStay(Collider other) {
Debug.Log(“Stay”);
}
// Trigger end is called
void OnTriggerExit(Collider other) {
Debug.Log(“Exit”);
}
Impactor
R.velocity=vector3;
1. There must be a collider (Box Collider)
2. An object must have a rigid body (Rigidbody)
Debug.Log(“enter”);
Debug.Log(collision.gameObject.name);
}
// Every frame of collision contact is called
void OnCollisionStay(Collision collision) {
Debug.Log(“Stay”);
}
// Collision end is called
void OnCollisionExit(Collision collision) {
Debug.Log(“Exit”);
}
Character controller
Void onControllerColliderHit(ControllerColliderHit hit){}
//mesh collider Mesh collider
//mesh renderer Mesh rendering is often used in animation
// Point multiplication
float h = Vector3.Dot(transform.forward, cube.transform.position - transform.position);
H>0 front
// Cross riding
Vector3 pos = Vector3.Cross(cube.transform.position,transform.position);
Pos.y Greater than 0 The player is on the right of the enemy
Pos.y Less than 0 The player is on the left of the enemy
Four elements ( a key )
1.Quaternion.LookRotation(vector3,vector3);
Be careful : The previous parameter is vector3, The latter parameter is above itself
transform.rotation = Quaternion.LookRotation(player.position - transform.position, Vector3.up);// Watch the player spin , Rotate with the player
Quaternion.LookRotation(new Vector3(dis.x, 0, dis.z));// Towards the player , Look at the player
2.Quaternion.Angle(transfrom.rotation,target.rotation)
How many degrees does it rotate relative to another object
Quaternion.Angle(transform.rotation, player.rotation);// Rotation angle ( How much angle does it rotate relative to another object )
3.Vector3.Angle(Vector3,vector3);
The angle between two objects
Vector3.Angle(transform.position, player.position - transform.position);// Dot multiply the included angle ( The angle between two points )
4.Quaternion.Euler(x,y,z)
Rotate the specified angle
5.Quaternion.Slerp(transfrom.rotation,to targer.rotation,Time.timespeed) Spherical difference
From the current perspective to the target perspective , The third parameter is speed
6.Quaternion.Lerp(transfrom.rotation,player.rotation,Time.deltaTime3);
and Slerp The effect is the same , Than Slerp good
Case study : The third person camera follows
public class FollowPlayer : MonoBehaviour {
private Transform player;
public float speed = 2;
void Start () {
// Get the objects in the game through the tag
player = GameObject.FindWithTag(“Player”).transform;
}
void Update () {
if (player != null)
{
// Calculate the target position of the camera , That is, the position of the player character + The offset value of the camera
Vector3 targetPos = player.position + new Vector3(0, 11.42F, -13.5F);
// Set camera position
transform.position = Vector3.Lerp(transform.position, targetPos, speed * Time.deltaTime);
// Calculate the rotation angle of the camera facing the player character
Quaternion targetRotation = Quaternion.LookRotation(player.position - transform.position);
// Set camera rotation
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
}
}
边栏推荐
- "Measuring curve length" of CAD dream drawing
- Understand encodefloatrgba and decodefloatrgba
- Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
- Unity get component
- [groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
- Wenet: E2E speech recognition tool for industrial implementation
- Introduction to JVM principle and process
- 3dsmax scanning function point connection drawing connection line
- Unity connects to the database
- [groovy] closure (closure as function parameter | code example)
猜你喜欢
How to choose a panoramic camera that suits you?
[crampon game] MC tutorial - first day of survival
Create a pyGame window with a blue background
Use assimp library to read MTL file data
Wan broadband access technology V EPON Technology
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
Séparation et combinaison de la construction du système qualité
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
AutoCAD - feature matching
随机推荐
The remainder operation is a hash function
jmeter -- 分布式压测
MD5绕过
3dsmax snaps to frozen objects
AutoCAD -- dimension break
Function overloading
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9
AutoCAD - feature matching
PostgreSQL 超越 MySQL,“世界上最好的编程语言”薪水偏低
AutoCAD - Document Management
AutoCAD - continuous annotation
2021 Higher Education Club Cup mathematical modeling national tournament ABCD problem - problem solving ideas
Leetcode 222 number of nodes of complete binary tree
669. 修剪二叉搜索树 ●●
[Business Research Report] Research Report on male consumption trends in other economic times -- with download link
2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
SQLServer 存储过程传递数组参数
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
3dsmax scanning function point connection drawing connection line