Advertisement
jretchy

Untitled

Mar 18th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. public float camSize;
  2. public float camSizeLimit;
  3. public float increment;
  4. public float timeLerp;
  5. public float timeLerpValue;
  6.  
  7. public bool shouldZoomIn = false;
  8. public bool shouldZoomOut = false;
  9.  
  10.  
  11.  
  12. private void Update()
  13. {
  14. if (shouldZoomIn)
  15. {
  16. ZoomIn();
  17. }
  18. else if (shouldZoomOut)
  19. {
  20. ZoomOut();
  21. }
  22.  
  23. camSize = Camera.main.orthographicSize;
  24. timeLerpValue = timeLerp * Time.deltaTime;
  25.  
  26.  
  27.  
  28. }
  29.  
  30. void ZoomOut()
  31. {
  32. if (Camera.main.orthographicSize < camSizeLimit)
  33. {
  34. Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, Camera.main.orthographicSize + increment, timeLerp * Time.deltaTime);
  35. }
  36. else if (Camera.main.orthographicSize > camSizeLimit)
  37. {
  38. shouldZoomOut = false;
  39. }
  40. }
  41.  
  42. void ZoomIn()
  43. {
  44. if (Camera.main.orthographicSize > 9.665403f)
  45. {
  46. Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, Camera.main.orthographicSize + -increment, timeLerp * Time.deltaTime);
  47. }
  48. else if (Camera.main.orthographicSize < 9.665403f)
  49. {
  50. shouldZoomIn = false;
  51. }
  52.  
  53. }
  54.  
  55. private void OnTriggerEnter2D(Collider2D col)
  56. {
  57. if (col.gameObject.tag == "ZoomInTrigger")
  58. {
  59. shouldZoomIn = true;
  60. }
  61. else if (col.gameObject.tag == "ZoomOutTrigger")
  62. {
  63. shouldZoomOut = true;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement