CameraMovement.cs 881 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. namespace DunGen.Demo
  3. {
  4. public class CameraMovement : MonoBehaviour
  5. {
  6. public float MovementSpeed = 100;
  7. private void Start()
  8. {
  9. var runtimeDungeon = UnityUtil.FindObjectByType<RuntimeDungeon>();
  10. if (runtimeDungeon != null)
  11. transform.forward = -runtimeDungeon.Generator.UpVector;
  12. }
  13. private void Update()
  14. {
  15. Vector3 direction = Vector3.zero;
  16. direction += transform.up * Input.GetAxisRaw("Vertical");
  17. direction += transform.right * Input.GetAxisRaw("Horizontal");
  18. direction.Normalize();
  19. Vector3 offset = direction * MovementSpeed * Time.deltaTime;
  20. if (Input.GetKey(KeyCode.LeftShift))
  21. offset *= 2;
  22. float zoom = Input.GetAxisRaw("Mouse ScrollWheel");
  23. offset += transform.forward * zoom * Time.deltaTime * MovementSpeed * 100;
  24. transform.position += offset;
  25. }
  26. }
  27. }