Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraZoom : MonoBehaviour {
- // Field of view maximum zoom
- int zoomsize = 20;
- // Field of view normal zoom
- int normal = 60;
- // Smooth..
- float smooth = 5;
- // bool for in/out zoom test
- bool iszoomed = false;
- // bunny transform
- public Transform player;
- // Starting camera transform (fix it)
- public Transform camerapos;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if(camerapos == null)
- camerapos = transform;
- player = GameObject.FindWithTag("Player").transform;
- //right click
- if (Input.GetMouseButtonDown(1))
- {
- iszoomed = !iszoomed;
- }
- if (iszoomed == true)
- {
- // actual position = all player.position except z (to avoid " Invisible bunny " bug)
- transform.position = new Vector3(player.position.x,player.position.y,transform.position.z);
- // Zoom in bunny!
- camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, zoomsize, Time.deltaTime * smooth);
- }
- else
- {
- // actual position = Starting camera position (fix it!)
- transform.position = camerapos.position;
- // zoom out
- camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, normal, Time.deltaTime * smooth);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment