Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class CameraZoom : MonoBehaviour
  6. {
  7.     public GameObject playah;
  8.     public GameObject cameraPoint;
  9.  
  10.     public UnityEngine.UI.Text camZoomText;
  11.  
  12.     public float smoothTime = 1.5f;
  13.     private float yVelocity = 0f;
  14.     private Vector3 camVelocity = Vector3.zero;
  15.     private float ballVelocityX;
  16.     private float ballVelocityY;
  17.     private float ballVelocity;
  18.  
  19.  
  20.     void Start ()
  21.     {
  22.        
  23.     }
  24.    
  25.     void Update ()
  26.     {
  27.         transform.position = Vector3.SmoothDamp (transform.position, cameraPoint.transform.position, ref camVelocity, smoothTime / 8f);
  28.  
  29.  
  30.  
  31.         ballVelocityX = playah.rigidbody2D.velocity.x;
  32.         ballVelocityY = playah.rigidbody2D.velocity.y;
  33.  
  34.         if (ballVelocityX < 0f)
  35.         {
  36.             ballVelocityX = ballVelocityX * (-1);
  37.         }
  38.         if (ballVelocityY < 0f)
  39.         {
  40.             ballVelocityY = ballVelocityY * (-1);
  41.         }
  42.         ballVelocity = ballVelocityX + ballVelocityY;
  43.  
  44.         float zoomTarget = ballVelocity / 3;
  45.         camera.orthographicSize = Mathf.SmoothDamp(camera.orthographicSize, zoomTarget, ref yVelocity, smoothTime);
  46.  
  47.         if (camera.orthographicSize < 4f)
  48.         {
  49.             camera.orthographicSize = 4f;
  50.         }
  51.         if (camera.orthographicSize > 7f)
  52.         {
  53.             camera.orthographicSize = 7f;
  54.         }
  55.  
  56.         camZoomText.text = "Camera Zoom  (please ignore): " + camera.orthographicSize.ToString("0.##");
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement