当前位置:网站首页>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);
}
}
}
边栏推荐
- Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
- [groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
- Download the details and sequence of the original data access from the ENA database in EBI
- 2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis
- AutoCAD -- dimension break
- 【acwing】836. Merge sets
- AutoCAD - Zoom previous
- Emlog博客主题模板源码简约好看响应式
- AutoCAD - Center zoom
- Flink cluster configuration
猜你喜欢

Special information | finance, accounting, audit - 22.1.23

2022 thinking of Mathematical Modeling B problem of American college students / analysis of 2022 American competition B problem

PostgreSQL surpasses mysql, and the salary of "the best programming language in the world" is low

Download the details and sequence of the original data access from the ENA database in EBI

计组笔记(1)——校验码、原补码乘除计算、浮点数计算

Looking at Chinese science and technology from the Winter Olympics: what is the mystery of the high-speed camera that the whole people thank?

Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation

介绍汉明距离及计算示例

Emlog blog theme template source code simple good-looking responsive

2022 American College Students' mathematical modeling ABCDEF problem thinking /2022 American match ABCDEF problem analysis
随机推荐
Mode in BST (binary tree & Notes on question brushing)
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
计组笔记(1)——校验码、原补码乘除计算、浮点数计算
LeetCode之单词搜索(回溯法求解)
Unity and database
Personal required code
AutoCAD - full screen display
JVM 原理和流程简介
AutoCAD -- dimension break
2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
2021-10-29
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
JMeter -- distributed pressure measurement
flutter 对象和列表
Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]
49 pictures and 26 questions explain in detail what is WiFi?
Use assimp library to read MTL file data
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
C4D simple cloth (version above R21)
Interface joint commissioning test script optimization V5.0 (end)