PlayerControllerTransform.cs 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerControllerTransform : MonoBehaviour {
  5. private string MoveInputAxis = "Vertical";
  6. private string TurnInputAxis = "Horizontal";
  7. // rotation that occurs in angles per second holding down input
  8. public float rotationRate = 360;
  9. // units moved per second holding down move input
  10. public float moveSpeed = 2;
  11. // Update is called once per frame
  12. private void Update ()
  13. {
  14. float moveAxis = Input.GetAxis(MoveInputAxis);
  15. float turnAxis = Input.GetAxis(TurnInputAxis);
  16. ApplyInput(moveAxis, turnAxis);
  17. }
  18. private void ApplyInput(float moveInput,
  19. float turnInput)
  20. {
  21. Move(moveInput);
  22. Turn(turnInput);
  23. }
  24. private void Move(float input)
  25. {
  26. transform.Translate(Vector3.forward * input * moveSpeed);
  27. }
  28. private void Turn(float input)
  29. {
  30. transform.Rotate(0, input * rotationRate * Time.deltaTime, 0);
  31. }
  32. }