-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraZoom.cs
30 lines (26 loc) · 1.01 KB
/
CameraZoom.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using UnityEngine;
using System.Collections;
public class CameraZoom : MonoBehaviour {
public int playerNum;
public float zoomSpeed;
void Update () {
if(camera.orthographic){
if(camera.orthographicSize >= 0){
camera.orthographicSize += Input.GetAxis("Zoom " + playerNum) * zoomSpeed * Time.deltaTime;
} else {
camera.orthographicSize = 0;
}
}else{
if(camera.transform.position.z > minZ && camera.transform.position.z < maxZ){
//camera.transform.position += ;
camera.transform.position = new Vector3(camera.transform.position.x,camera.transform.position.y,
camera.transform.position.z + (Input.GetAxis("Zoom " + playerNum) * zoomSpeed * Time.deltaTime));
}
if(camera.transform.position.z > maxZ){
camera.transform.position = new Vector3(camera.transform.position.x,camera.transform.position.y,maxZ);
}else if(camera.transform.position.z < minZ){
camera.transform.position = new Vector3(camera.transform.position.x,camera.transform.position.y,minZ);
}
}
}
}