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.

52 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. public float characterSpeed;
  14. #endregion Unity Functions
  15. #region Unity Functions
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. if (character == null)
  20. return;
  21. if (Input.GetKeyDown(KeyCode.LeftArrow))
  22. {
  23. character.Rotate(Direction.Left);
  24. }
  25. if (Input.GetKeyDown(KeyCode.RightArrow))
  26. {
  27. character.Rotate(Direction.Right);
  28. }
  29. if (Input.GetKeyDown(KeyCode.UpArrow))
  30. {
  31. character.Move(Direction.Forward, characterSpeed);
  32. }
  33. if (Input.GetKeyDown(KeyCode.Space))
  34. {
  35. character.Jump(Direction.Forward);
  36. }
  37. }
  38. //if character is empty check on object for it
  39. private void OnValidate()
  40. {
  41. if (character == null)
  42. character = GetComponent<Character>();
  43. }
  44. #endregion Unity Functions
  45. }