PlayerCamera.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. // This sets up the scene camera for the local player
  4. namespace Mirror.Examples.TanksCoop
  5. {
  6. public class PlayerCamera : NetworkBehaviour
  7. {
  8. Camera mainCam;
  9. void Awake()
  10. {
  11. mainCam = Camera.main;
  12. }
  13. public override void OnStartLocalPlayer()
  14. {
  15. if (mainCam != null)
  16. {
  17. // configure and make camera a child of player with 3rd person offset
  18. mainCam.orthographic = false;
  19. mainCam.transform.SetParent(transform);
  20. mainCam.transform.localPosition = new Vector3(0f, 6f, -11f);
  21. mainCam.transform.localEulerAngles = new Vector3(25f, 0f, 0f);
  22. }
  23. else
  24. Debug.LogWarning("PlayerCamera: Could not find a camera in scene with 'MainCamera' tag.");
  25. }
  26. public override void OnStopLocalPlayer()
  27. {
  28. if (mainCam != null)
  29. {
  30. mainCam.transform.SetParent(null);
  31. SceneManager.MoveGameObjectToScene(mainCam.gameObject, SceneManager.GetActiveScene());
  32. mainCam.orthographic = true;
  33. mainCam.orthographicSize = 15f;
  34. mainCam.transform.localPosition = new Vector3(0f, 70f, 0f);
  35. mainCam.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
  36. }
  37. }
  38. }
  39. }