Fearsoulfire

StillWrongAI

Aug 15th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraZoom : MonoBehaviour {
  5.     // Field of view maximum zoom
  6.     int zoomsize = 20;
  7.     // Field of view normal zoom
  8.     int normal = 60;
  9.     // Smooth..
  10.     float smooth = 5;
  11.     // bool for in/out zoom test
  12.     bool iszoomed = false;
  13.     // bunny transform
  14.     public Transform player;
  15.     // Starting camera transform (fix it)
  16.     public Transform camerapos;
  17.    
  18.     // Use this for initialization
  19.     void Start () {        
  20.        
  21.  
  22.     }
  23.    
  24.     // Update is called once per frame
  25.     void Update () {
  26.         if(camerapos == null)
  27.         camerapos = transform;
  28.  
  29.         player = GameObject.FindWithTag("Player").transform;
  30.         //right click
  31.         if (Input.GetMouseButtonDown(1))
  32.         {
  33.             iszoomed = !iszoomed;
  34.         }
  35.         if (iszoomed == true)
  36.         {
  37.             // actual position = all player.position except z (to avoid " Invisible bunny " bug)
  38.             transform.position = new Vector3(player.position.x,player.position.y,transform.position.z);
  39.             // Zoom in bunny!
  40.             camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, zoomsize, Time.deltaTime * smooth);
  41.         }
  42.         else
  43.         {
  44.             // actual position = Starting camera position (fix it!)
  45.             transform.position = camerapos.position;
  46.             // zoom out
  47.             camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, normal, Time.deltaTime * smooth);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment