KEYCODE_A
How do I use K E Y C O D E_ A
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
137 | if( Input.GetKey( KeyCode.A ) == true ) | 1 |
44 | if (Input.GetKey(KeyCode.A)) | 2 |
84 | if (Input.GetKey(KeyCode.A)) | 3 |
File name: RPGMovement.cs
Copy
135 void UpdateRotateMovement()
136 {
137 if( Input.GetKey( KeyCode.A ) == true )
138 {
139 m_CurrentTurnSpeed = -RotateSpeed;
140 transform.Rotate( 0, -RotateSpeed * Time.deltaTime, 0 );
141 }
142
143 if( Input.GetKey( KeyCode.D ) == true )
144 {
145 m_CurrentTurnSpeed = RotateSpeed;
146 transform.Rotate( 0, RotateSpeed * Time.deltaTime, 0 );
147 }
148 }
File name: MoveByKeys.cs
Copy
37 public void FixedUpdate()
38 {
39 if (!photonView.isMine)
40 {
41 return;
42 }
43
44 if (Input.GetKey(KeyCode.A))
45 {
46 transform.position += Vector3.left*(this.Speed*Time.deltaTime);
47 }
48
49 if (Input.GetKey(KeyCode.D))
50 {
51 transform.position += Vector3.right*(this.Speed*Time.deltaTime);
52 }
53
54 // jumping has a simple "cooldown" time but you could also jump in the air
55 if (this.jumpingTime <= 0.0f)
56 {
57 if (this.body != null || this.body2d != null)
58 {
59 // obj has a Rigidbody and can jump (AddForce)
60 if (Input.GetKey(KeyCode.Space))
61 {
62 this.jumpingTime = this.JumpTimeout;
63
64 Vector2 jump = Vector2.up*this.JumpForce;
65 if (this.body2d != null)
66 {
67 this.body2d.AddForce(jump);
68 }
69 else if (this.body != null)
70 {
71 this.body.AddForce(jump);
72 }
73 }
74 }
75 }
76 else
77 {
78 this.jumpingTime -= Time.deltaTime;
79 }
80
81 // 2d objects can't be moved in 3d "forward"
82 if (!this.isSprite)
83 {
84 if (Input.GetKey(KeyCode.W))
85 {
86 transform.position += Vector3.forward*(this.Speed*Time.deltaTime);
87 }
88
89 if (Input.GetKey(KeyCode.S))
90 {
91 transform.position -= Vector3.forward*(this.Speed*Time.deltaTime);
92 }
93 }
94 }
File name: PlayerControl.cs
Copy
71 void MovementControls()
72 {
73 float screenSpeed = 0;
74 float horizontalInput = 0;
75 float verticalInput = 0;
76
77 screenSpeed = CameraMotor.speedScreen;
78
79 //moving right
80 if (Input.GetKey(KeyCode.D))
81 horizontalInput = speedCurrent;
82
83 //moving left
84 if (Input.GetKey(KeyCode.A))
85 horizontalInput = -speedCurrent;
86
87 //moving up
88 if (Input.GetKey(KeyCode.W))
89 verticalInput = speedCurrent;
90
91 //moving down
92 if (Input.GetKey(KeyCode.S))
93 verticalInput = -speedCurrent;
94
95
96 //result velocity
97 rb.velocity = new Vector3(horizontalInput, 0, screenSpeed + verticalInput);
98 }
KEYCODE_A 123 lượt xem
Gõ tìm kiếm nhanh...