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.

57 lines
1.6 KiB

5 years ago
5 years ago
  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. StartCoroutine(character.RotateToDirection(Direction.Left, Character.Animation.Jump, characterSpeed, true));
  24. }
  25. if (Input.GetKeyDown(KeyCode.RightArrow))
  26. {
  27. StartCoroutine(character.RotateToDirection(Direction.Right, Character.Animation.Jump, characterSpeed, true));
  28. }
  29. if (Input.GetKeyDown(KeyCode.UpArrow))
  30. {
  31. float outTime;
  32. Move move = (Move)ScriptableObject.CreateInstance(typeof(Move));
  33. StartCoroutine(move.Run(character, characterSpeed));
  34. Destroy(move);
  35. }
  36. if (Input.GetKeyDown(KeyCode.Space))
  37. {
  38. float outTime;
  39. Jump jump = (Jump)ScriptableObject.CreateInstance(typeof(Jump));
  40. StartCoroutine(jump.Run(character, characterSpeed));
  41. Destroy(jump);
  42. }
  43. }
  44. //if character is empty check on object for it
  45. private void OnValidate()
  46. {
  47. if (character == null)
  48. character = GetComponent<Character>();
  49. }
  50. #endregion Unity Functions
  51. }