ViewControl.cs 905 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ViewControl : MonoBehaviour {
  6. [Header("Camera")]
  7. public Camera cam;
  8. public CanvasScaler canvasScl; //Leave empty if no UI canvas to attach to this camera
  9. ViewControl[] camControllers;
  10. [Header("Scale")]
  11. public Vector2 camScale = new Vector2 (0.45f, 0.45f);
  12. [Header("Position")]
  13. public Vector2 camPos;
  14. /// <summary>
  15. /// Get needed variables.
  16. /// </summary>
  17. private void Start()
  18. {
  19. cam = GetComponent<Camera>();
  20. camControllers = FindObjectsOfType<ViewControl>();
  21. }
  22. private void Update()
  23. {
  24. //Update this camera's rect
  25. cam.rect = new Rect(camPos, camScale);
  26. //And its canvas
  27. if(canvasScl != null)
  28. canvasScl.scaleFactor = camScale.x;
  29. }
  30. }