unity camera tremolante code example
Example 1: unity camera movement script
using UnityEngine;
public class CameraController : MonoBehaviour {
private float moveSpeed = 0.5f;
private float scrollSpeed = 10f;
void Update () {
if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) {
transform.position += moveSpeed * new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
}
if (Input.GetAxis("Mouse ScrollWheel") != 0) {
transform.position += scrollSpeed * new Vector3(0, -Input.GetAxis("Mouse ScrollWheel"), 0);
}
}
}
Example 2: camera zooming in unity
using UnityEngine;
using System.Collections;
public class MouseWheelZoom : MonoBehaviour {
float curZoomPos, zoomTo;
float zoomFrom = 20f;
void Update ()
{
float y = Input.mouseScrollDelta.y;
if (y >= 1)
{
zoomTo -= 5f;
Debug.Log ("Zoomed In");
}
else if (y >= -1) {
zoomTo += 5f;
Debug.Log ("Zoomed Out");
}
curZoomPos = zoomFrom + zoomTo;
curZoomPos = Mathf.Clamp (curZoomPos, 5f, 35f);
zoomTo = Mathf.Clamp (zoomTo, -15f, 30f);
Camera.main.fieldOfView = curZoomPos;
}