- Platformer2DUserControl.cs
- Scripts /
- 2D /
- Standard Assets /
- Assets /
- project /
1 using System;
2 using UnityEngine;
3 using UnityStandardAssets.CrossPlatformInput;
4
5 namespace UnityStandardAssets._2D
6 {
7 [RequireComponent(typeof (PlatformerCharacter2D))]
8 public class Platformer2DUserControl : MonoBehaviour
9 {
10 private PlatformerCharacter2D m_Character;
11 private bool m_Jump;
12
13
14 private void Awake()
15 {
16 m_Character = GetComponent<PlatformerCharacter2D>();
17 }
18
19
20 private void Update()
21 {
22 if (!m_Jump)
23 {
24 // Read the jump input in Update so button presses aren't missed.
25 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
26 }
27 }
28
29
30 private void FixedUpdate()
31 {
32 // Read the inputs.
33 bool crouch = Input.GetKey(KeyCode.LeftControl);
34 float h = CrossPlatformInputManager.GetAxis("Horizontal");
35 // Pass all parameters to the character control script.
36 m_Character.Move(h, crouch, m_Jump);
37 m_Jump = false;
38 }
39 }
40 }
2 using UnityEngine;
3 using UnityStandardAssets.CrossPlatformInput;
4
5 namespace UnityStandardAssets._2D
6 {
7 [RequireComponent(typeof (PlatformerCharacter2D))]
8 public class Platformer2DUserControl : MonoBehaviour
9 {
10 private PlatformerCharacter2D m_Character;
11 private bool m_Jump;
12
13
14 private void Awake()
15 {
16 m_Character = GetComponent<PlatformerCharacter2D>();
17 }
18
19
20 private void Update()
21 {
22 if (!m_Jump)
23 {
24 // Read the jump input in Update so button presses aren't missed.
25 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
26 }
27 }
28
29
30 private void FixedUpdate()
31 {
32 // Read the inputs.
33 bool crouch = Input.GetKey(KeyCode.LeftControl);
34 float h = CrossPlatformInputManager.GetAxis("Horizontal");
35 // Pass all parameters to the character control script.
36 m_Character.Move(h, crouch, m_Jump);
37 m_Jump = false;
38 }
39 }
40 }