KEYCODE_S
How do I use K E Y C O D E_ S
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: JumpAndRunMovement.cs
Copy
52 void UpdateJumping()
53 {
54 if( Input.GetKey( KeyCode.Space ) == true && m_IsGrounded == true )
55 {
56 m_Animator.SetTrigger( "IsJumping" );
57 m_Body.AddForce( Vector2.up * JumpForce );
58 m_PhotonView.RPC( "DoJump", PhotonTargets.Others );
59 }
60 }
File name: RPGMovement.cs
Copy
114 void UpdateBackwardMovement()
115 {
116 if( Input.GetKey( KeyCode.S ) == true )
117 {
118 m_CurrentMovement = -transform.forward * BackwardSpeed;
119 }
120 }
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: PlayerMoveScript.cs
Copy
50 void Update () {
51
52 grounded = Physics2D.OverlapCircle(groundCheck.position, groundChecked, isGround);
53
54 if(transform.position.x > speedCount) {
55 speedCount += speedIncrease;
56 speedIncrease = speedIncrease * speedMultiplier;
57 moveSpeed = moveSpeed * speedMultiplier;
58 }
59
60 rigidbody.velocity = new Vector2 (moveSpeed, rigidbody.velocity.y);
61
62 if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
63
64 if(grounded) {
65 rigidbody.velocity = new Vector2 (rigidbody.velocity.x, jumpForce);
66 anim.SetTrigger ("Jump");
67 stopJumping = false;
68 }
69 }
70
71 if((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && !stopJumping) {
72 if(jumpTimeCounter > 0) {
73 rigidbody.velocity = new Vector2 (rigidbody.velocity.x, jumpForce);
74 jumpTimeCounter -= Time.deltaTime;
75 }
76 }
77
78 if(Input.GetKeyUp (KeyCode.Space) || Input.GetMouseButtonUp(0)) {
79 jumpTimeCounter = 0;
80 stopJumping = true;
81 }
82
83 if(grounded) {
84 jumpTimeCounter = jumpTime;
85 }
86
87
88 scoreCount += pointsPerSeconds = Time.deltaTime;
89
90 if(scoreCount > highScoreCount) {
91 highScoreCount = scoreCount;
92
93 }
94 scoreText.text = "Score: " + Mathf.Round(scoreCount);
95
96 }
File name: PlayerControl.cs
Copy
49 void ShootOrPauseControls()
50 {
51 if (!SystemScr.paused)
52 {
53 if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
54 {
55 GameObject p_bullet = pools.GetPoolableObject("p_bullet");
56
57 if (p_bullet != null && maxBulletsOnScreen > 0)
58 {
59 sounds.PlaySoundsPlayer(0);
60 p_bullet.SetActive(true);
61 p_bullet.GetComponent
62 }
63 }
64 }
65 if (Input.GetKeyDown(KeyCode.Escape))
66 {
67 ui.Pause_btn();
68 }
69 }
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 }
File name: Cannon.cs
Copy
120 void CannonShoot(){
121 if (Input.GetKey (KeyCode.Space)) {
122 if(shot != 0){
123 UpdatePowerLevel ();
124 }
125 }else if(Input.GetKeyUp(KeyCode.Space)){
126 if (shot != 0) {
127 GameObject newCannonBullet = Instantiate (cannonBullet, cannonTip.position, Quaternion.identity) as GameObject;
128 newCannonBullet.transform.GetComponent
129 if (GameController.instance != null && MusicController.instance != null) {
130 if (GameController.instance.isMusicOn) {
131 audioSource.PlayOneShot (cannonShot);
132 }
133 }
134 shot--;
135 powerLevel.value = 0;
136 readyToShoot = false;
137 }
138 }
139
140 }
File name: GameScreen.cs
Copy
379 public void LateUpdate()
380 {
381 if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
382 {
383 if (InputController.Name == InputNames.GAMESCREEN)
384 {
385 if (InputController.IsScreen)
386 {
387 if(Time.timeScale != 0)
388 animals.getAnimal(0).GetComponent
389 //createBuiTien(-1.2f, 1f);
390 }
391 }
392 }
393 else if (Input.GetMouseButtonUp(0))
394 {
395 InputController.IsScreen = true;
396 }
397 if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Backspace))
398 {
399 if (!isPrepare)
400 {
401 if (dialog != null && dialog.activeSelf && InputController.Name == InputNames.DIALOG)
402 {
403 dialog.GetComponent
404 pauseLayer.SetActive(true);
405 }else if (InputController.Name == InputNames.GAMESCREEN)
406 {
407 pauseGame();
408 dialog.GetComponent
409 pauseLayer.SetActive(false);
410 }
411 else if (pauseLayer.activeSelf)
412 {
413 resumeGame();
414 }
415 }
416 }
417 if (isPrepare)
418 {
419 isPrepare = false;
420
421 buttonSkills.setFonts(shopFont);
422 prepareGame();
423 }
424 }
KEYCODE_S 130 lượt xem
Gõ tìm kiếm nhanh...