JumpTimeout
How do I use Jump Timeout
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
62 | this.jumpingTime = this.JumpTimeout; | 1 |
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 }
JumpTimeout 162 lượt xem
Gõ tìm kiếm nhanh...