zoom with mouse scrolling

hello

I want to make zoom camera with mouse scrolling, but I don’t know how to make program to get it when I’m scrolling mouse and in which direction.

this is camera and what I want to modify with scrolling:

I was looking in help file and I found only EventType.ScrollWheel and I don’t know how to use that and it’s not explained in help file, and I think it can’t help me because it doesn’t indicates WHEN I scroll mouse wheel

I was trying to find anything related with mouse wheel scrolling in Event. (because it is similar to pressing button) but didn’t find anything, plz help.

This is a modification on the original MouseOrbit to include a non target and wheel mouse. Its probably not exactly what you want, but it has the parts for the wheel mouse in it. :wink:

var targetObj : Transform;
var wheelSpeed=2.0;
var minDistance = 20.0;
var maxDistance=50.0;
private var distance = minDistance;
private var currentDistance = maxDistance;

var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = -20;
var yMaxLimit = 80;

private var x = 0.0;
private var y = 0.0;

@script AddComponentMenu("Camera-Control/Mouse Orbit")

function Start () {
	var angles = transform.eulerAngles;
	x = angles.y;
	y = angles.x;

	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function LateUpdate () {
	var targetPos=Vector3.zero;
	if(targetObj)targetPos=targetObj.position;
	x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
	y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
	y = ClampAngle(y, yMinLimit, yMaxLimit);
	 		   
	var rotation = Quaternion.Euler(y, x, 0);
	var position = rotation * Vector3(0.0, 0.0, -distance) + targetPos;
	
	transform.rotation = rotation;
	transform.position = position;
	
	currentDistance -= Input.GetAxis("Mouse ScrollWheel") * wheelSpeed;
	currentDistance=Mathf.Clamp(currentDistance,minDistance, maxDistance);
	distance=Mathf.Lerp(distance, currentDistance, 2.0 * Time.deltaTime);
	
	transform.position=targetPos;
	transform.Translate(-Vector3.forward * distance);
}

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

nice I like that but that is not what I wanted, maybe I’ll need it later, cool thing, maybe I’ll need it later, it would be cool to spin around ONLY when I press shift button or something like that,

and I think it is easier to make it with function Transform.RotateAround

what I need is WHEN I rotate Mouse wheel to zoom in or zoom out

probably I’ll have to make any kind of code for starting, because people probably think that I haven’t tried to do anything, but problem is where to start, where too look in the help for functions which are controlled by mouse wheel

like when I have

if (Input.GetKey (KeyCode.W))
{
[COLOR="green"]DO SOMETHING TRIGGERED WITH "W" KEY[/COLOR]
}

now I need something like

if (Input.GetKey (KeyCode.[COLOR="red"]MouseWheelspin[/COLOR]))
{
[COLOR="green"]DO SOMETHING TRIGGERED WITH Mouse Wheel spin[/COLOR]
}

btw I’m writing in C#

Instead of Mouse Scroll i did it with Holding Shift + Holding LEFT mouse button + Mouse Drag

If anyone wants to see the code:

if (Input.GetMouseButton(0)  Input.GetKey (KeyCode.LeftShift))
{
	if (mouseDragOn1 == false)
	{
		mouse1drag1 = Input.mousePosition;
		mouseDragOn1 = true;
	}
	else
	{
		mouse1drag2 = Input.mousePosition;
		mouse1drag = mouse1drag2.y - mouse1drag1.y;
		camcurr = camera.orthographicSize;
		if (camera.orthographicSize<=70  mouse1drag>=0) camera.orthographicSize  = camcurr + mouse1drag/100;
		if (camera.orthographicSize>=10  mouse1drag<0)   camera.orthographicSize  = camcurr + mouse1drag/100;
	}
}
else mouseDragOn1 = false;

that is for zooming in and out
I also made for moving camera around with Holding Shift + Holding RIGHT mouse button + Mouse Drag

if (Input.GetMouseButton(1)  Input.GetKey (KeyCode.LeftShift))
{
	if (mouseDragOn2 == false)
	{
		mouse2drag1 = Input.mousePosition;
		mouseDragOn2 = true;
	}
	else
	{
		mouse2drag2 = Input.mousePosition;
		transform.Translate ((mouse2drag1-mouse2drag2)/500);
	}
}
else mouseDragOn2 = false;