PlayerCamera.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. // This sets up the scene camera for the local player
  4. namespace Mirror.Examples.AdditiveLevels
  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, 3f, -8f);
  21. mainCam.transform.localEulerAngles = new Vector3(10f, 0f, 0f);
  22. }
  23. }
  24. public override void OnStopLocalPlayer()
  25. {
  26. if (mainCam != null)
  27. {
  28. mainCam.transform.SetParent(null);
  29. SceneManager.MoveGameObjectToScene(mainCam.gameObject, SceneManager.GetActiveScene());
  30. mainCam.orthographic = true;
  31. mainCam.transform.localPosition = new Vector3(0f, 70f, 0f);
  32. mainCam.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
  33. }
  34. }
  35. }
  36. }