Platformer2DUserControl.cs 1.0 KB

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