Skip to content

Instantly share code, notes, and snippets.

@renews
Created March 12, 2015 21:53
Show Gist options
  • Save renews/2d063eda5d79721ca653 to your computer and use it in GitHub Desktop.
Save renews/2d063eda5d79721ca653 to your computer and use it in GitHub Desktop.
Unity - Camera Zoom With mouse
var ZoomAmount : float = 0; //With Positive and negative values
var MaxToClamp : float = 10;
var ROTSpeed : float = 10;
function Update() {
ZoomAmount += Input.GetAxis("Mouse ScrollWheel");
ZoomAmount = Mathf.Clamp(ZoomAmount, -MaxToClamp, MaxToClamp);
var translate = Mathf.Min(Mathf.Abs(Input.GetAxis("Mouse ScrollWheel")), MaxToClamp - Mathf.Abs(ZoomAmount));
gameObject.transform.Translate(0,0,translate * ROTSpeed * Mathf.Sign(Input.GetAxis("Mouse ScrollWheel")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment