当前位置:网站首页>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.right
h+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-=y
10;
cameraRotate.y-=x
10;
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.time
5,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.deltaTime
3);
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);
    }
}

}

原网站

版权声明
本文为[yaohuiyaoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140626298892.html