You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Debug class for controlling a character with keyboard input
  6. /// </summary>
  7. public class KeyboardInput : MonoBehaviour
  8. {
  9. #region Inspector Fields
  10. [SerializeField]
  11. [Tooltip("Character to move")]
  12. private Character character;
  13. #endregion Unity Functions
  14. #region Unity Functions
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. if (character == null)
  19. return;
  20. if (Input.GetKeyDown(KeyCode.LeftArrow))
  21. {
  22. character.Rotate(Direction.Left);
  23. }
  24. if (Input.GetKeyDown(KeyCode.RightArrow))
  25. {
  26. character.Rotate(Direction.Right);
  27. }
  28. if (Input.GetKeyDown(KeyCode.UpArrow))
  29. {
  30. character.Move(Direction.Forward);
  31. }
  32. if (Input.GetKeyDown(KeyCode.Space))
  33. {
  34. character.Jump(Direction.Forward);
  35. }
  36. }
  37. //if character is empty check on object for it
  38. private void OnValidate()
  39. {
  40. if (character == null)
  41. character = GetComponent<Character>();
  42. }
  43. #endregion Unity Functions
  44. }