- Home /
Circular zoom control?
I'm trying to make a zoom control for my game map I'm working on. I thought of ways to achieve this and had two options : 1) pinch zoom 2)circular slider zoom, and I prefer the latter because the user can view the map as he zooms rather than trying to scratch his screen...But how to do it? a horizontal slider is easy but how to change it to a circular one? Please, any help will appreciated.
I'm working on this myself but quite short on ideas right now coz been learning unity not for long...to support my question sneak a peek on this pic: (from Google!)
Answer by robertbu · Oct 05, 2013 at 03:38 AM
What I would do is use the change of angle frame to frame to change some value.
#pragma strict
private var startAngle;
var speed = 1.0;
var minSize;
var maxSize;
function OnMouseDown() {
var pos = Input.mousePosition;
pos.z = transform.position.z - Camera.main.transform.position.z;
pos = Camera.main.ScreenToWorldPoint(pos);
pos = pos - transform.position;
startAngle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
}
function OnMouseDrag() {
var pos = Input.mousePosition;
pos.z = transform.position.z - Camera.main.transform.position.z;
pos = Camera.main.ScreenToWorldPoint(pos);
pos = pos - transform.position;
var angle = Mathf.Atan2(pos.y, pos.x) * Mathf.Rad2Deg;
Debug.Log("Delta angle: "+Mathf.DeltaAngle(angle,startAngle));
startAngle = angle;
}
Put this on a visible object with a collider. While running, click on the outer edge of the object and rotate around. Note you can reverse the parameters in the DeltaAngle() call to reverse the polarity.
To adapt the answer @robertbu provided for touch replace Input.mousePostion with Input.GetTouch(0).position