Created
March 12, 2015 21:53
-
-
Save renews/2d063eda5d79721ca653 to your computer and use it in GitHub Desktop.
Unity - Camera Zoom With mouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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