Test de communication de paquets entre un client et un serveur
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CameraController.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CameraController : MonoBehaviour
  5. {
  6. public PlayerManager player;
  7. public float sensitivity = 100f;
  8. public float clampAngle = 85f;
  9. private float verticalRotation;
  10. private float horizontalRotation;
  11. private void Start()
  12. {
  13. verticalRotation = transform.eulerAngles.x;
  14. horizontalRotation = transform.eulerAngles.y;
  15. }
  16. private void Update()
  17. {
  18. if (Input.GetKeyDown(KeyCode.Escape))
  19. {
  20. ToggleCursorMode();
  21. }
  22. if (Cursor.lockState == CursorLockMode.Locked)
  23. {
  24. Look();
  25. }
  26. Debug.DrawRay(transform.position, transform.forward * 2, Color.red);
  27. }
  28. private void Look()
  29. {
  30. float _mouseVertical = -Input.GetAxis("Mouse Y");
  31. float _mouseHorizontal = Input.GetAxis("Mouse X");
  32. verticalRotation += _mouseVertical * sensitivity * Time.deltaTime;
  33. horizontalRotation += _mouseHorizontal * sensitivity * Time.deltaTime;
  34. verticalRotation = Mathf.Clamp(verticalRotation, -clampAngle, clampAngle);
  35. transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
  36. player.transform.rotation = Quaternion.Euler(0 , horizontalRotation, 0);
  37. }
  38. private void ToggleCursorMode()
  39. {
  40. Cursor.visible = !Cursor.visible;
  41. if (Cursor.lockState == CursorLockMode.None)
  42. {
  43. Cursor.lockState = CursorLockMode.Locked;
  44. }
  45. else
  46. {
  47. Cursor.lockState = CursorLockMode.None;
  48. }
  49. }
  50. }