All pastes #2107627 Raw Edit

Bare bones Unity JS camera scrip

public javascript v1 · immutable
#2107627 ·published 2012-01-30 03:37 UTC
rendered paste body
var target : Transform;var Distance = 10.0;var MaxDistance = 15.0;var MinDistance = 5.0;var xSpeed = 125.0;var ySpeed = 50.0;var position;private var x = 0.0;private var y = 0.0;function Start () {}function LateUpdate () {    		var rotation = Quaternion.Euler(y, x, 0);                transform.rotation = rotation; //Rotate the camera to those angles                 position = rotation * Vector3(0, 3.0, -Distance) + target.position;                transform.position = position;            	position = rotation * Vector3(0, 3.0, -Distance) + target.position;	    if(target) {        	if(Input.GetMouseButton(1)) {    		    		//Change the angles by mouse input        	x += Input.GetAxis("Mouse X") * xSpeed * 0.02;        	y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;                           	 	}   	    	 	if(Input.GetAxis("Mouse ScrollWheel") < 0) { // If the scroll wheel is being scrolled down   	 	   	 		if(Distance <= 200)	{   	 		   	 			Distance += 5;   	 		}   	 	}   	 	   	 	if(Input.GetAxis("Mouse ScrollWheel") > 0) { // If the scroll whell is being scrolled up   	 	   	 		if(Distance >= 20) {   	 		   	 			Distance -= 5;   	 		}   	 	}   	    	    	 }   	 		}function ChangeTarget (NewTarget : Transform) { // Function used by System Select script to change camera focus	print ("Setting new target as " + NewTarget);	target = NewTarget;}