CameraMove.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CameraMove : MonoBehaviour
  5. {
  6. public float moveSpped = 100;
  7. public float roteSpped = 100;
  8. public float smooth = 2;
  9. public string horizontal = "Horizontal";
  10. public string vertical = "Vertical";
  11. public string mouseX = "Mouse X";
  12. public string mouseY = "Mouse Y";
  13. public string fire2 = "Fire2";
  14. public string mouseScrollWheel = "Mouse ScrollWheel";
  15. private Vector2 angele;
  16. private Quaternion rotation;
  17. private void Awake()
  18. {
  19. #if !UNITY_EDITOR
  20. enabled = false;
  21. #endif
  22. angele = transform.eulerAngles;
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. if (Input.GetButton(fire2))
  28. {
  29. angele.x -= Input.GetAxis(mouseY) * roteSpped * Time.deltaTime;
  30. angele.x = Mathf.Clamp(angele.x, -90, 90);
  31. angele.y += Input.GetAxis(mouseX) * roteSpped * Time.deltaTime;
  32. transform.eulerAngles = angele;
  33. }
  34. if (Input.GetButton(horizontal))
  35. {
  36. transform.Translate(transform.right.normalized * Input.GetAxis(horizontal) * Time.deltaTime * moveSpped, Space.World);
  37. }
  38. if (Input.GetButton(vertical))
  39. {
  40. transform.Translate(transform.forward.normalized * Input.GetAxis(vertical) * Time.deltaTime * moveSpped, Space.World);
  41. }
  42. }
  43. }