当前位置:网站首页>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);
}
}
}
边栏推荐
- AutoCAD - workspace settings
- English topic assignment (26)
- Understand encodefloatrgba and decodefloatrgba
- The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
- Data security -- 14 -- Analysis of privacy protection governance
- PR first time
- Flutter tips: various fancy nesting of listview and pageview
- 49 pictures and 26 questions explain in detail what is WiFi?
- Minor spanning tree
- Detailed introduction of OSPF header message
猜你喜欢
![[groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)](/img/03/329adb314606f29c8a4cb2260e84c8.jpg)
[groovy] closure (closure call is associated with call method | call () method is defined in interface | call () method is defined in class | code example)

【Leetcode】1352. 最后 K 个数的乘积

2022 thinking of mathematical modeling a problem of American college students / analysis of 2022 American competition a problem

Redis 排查大 key 的4种方法,优化必备

2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis

Thematic information | carbon, carbon neutrality, low carbon, carbon emissions - 22.1.9

stm32Cubemx(8):RTC和RTC唤醒中断

54. Spiral matrix & 59 Spiral matrix II ●●
![[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator](/img/cc/06580ce7b553182968d273841a78b4.jpg)
[AI bulletin 20220211] the hard core up owner has built a lidar and detailed AI accelerator
![[Business Research Report] top ten trends of science and technology and it in 2022 - with download link](/img/9f/4fc63fa7b0e9afc5dd638d4b599b2c.jpg)
[Business Research Report] top ten trends of science and technology and it in 2022 - with download link
随机推荐
China polyurethane rigid foam Market Research and investment forecast report (2022 Edition)
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
Data security -- 14 -- Analysis of privacy protection governance
mysql審計日志歸檔
English topic assignment (26)
中国针状焦行业发展研究与投资价值报告(2022版)
Pdf to DWG in CAD
3dsmax2018 common operations and some shortcut keys of editable polygons
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
MySQL audit log archiving
Solution of circular dependency
Special information | real estate and office buildings - 22.1.9
[groovy] closure closure (customize closure parameters | customize a single closure parameter | customize multiple closure parameters | specify the default value of closure parameters)
China as resin Market Research and investment forecast report (2022 Edition)
3dsmax common commands
Emlog博客主题模板源码简约好看响应式
GameObject class and transform class of unity
Introduction to JVM principle and process
Understand encodefloatrgba and decodefloatrgba
"Measuring curve length" of CAD dream drawing