CameraTarget.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using CodeMonkey.Utils;
  5. public class CameraTarget : MonoBehaviour {
  6. public enum Axis {
  7. XZ,
  8. XY,
  9. }
  10. [SerializeField] private Axis axis = Axis.XZ;
  11. [SerializeField] private float moveSpeed = 50f;
  12. private void Update() {
  13. float moveX = 0f;
  14. float moveY = 0f;
  15. if (Input.GetKey(KeyCode.W)) {
  16. moveY = +1f;
  17. }
  18. if (Input.GetKey(KeyCode.S)) {
  19. moveY = -1f;
  20. }
  21. if (Input.GetKey(KeyCode.A)) {
  22. moveX = -1f;
  23. }
  24. if (Input.GetKey(KeyCode.D)) {
  25. moveX = +1f;
  26. }
  27. Vector3 moveDir;
  28. switch (axis) {
  29. default:
  30. case Axis.XZ:
  31. moveDir = new Vector3(moveX, 0, moveY).normalized;
  32. break;
  33. case Axis.XY:
  34. moveDir = new Vector3(moveX, moveY).normalized;
  35. break;
  36. }
  37. if (moveX != 0 || moveY != 0) {
  38. // Not idle
  39. }
  40. if (axis == Axis.XZ) {
  41. moveDir = UtilsClass.ApplyRotationToVectorXZ(moveDir, 30f);
  42. }
  43. transform.position += moveDir * moveSpeed * Time.deltaTime;
  44. }
  45. }