2019-10-05 09:48:36 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(Camera))]
|
|
|
|
|
public class ZoomWithScrollWheel : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float zoomMultiplier;
|
|
|
|
|
public string zoomAxisName;
|
|
|
|
|
|
|
|
|
|
protected new Camera camera;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
camera = GetComponent<Camera>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2019-10-05 18:41:07 +00:00
|
|
|
|
float mouseWheel = Input.GetAxisRaw(zoomAxisName);
|
2019-10-05 09:48:36 +00:00
|
|
|
|
if(mouseWheel != 0) {
|
|
|
|
|
camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - mouseWheel * zoomMultiplier, 0, float.PositiveInfinity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|