Hi everybody!
I want to create specific tranformation of the camera: when I press GUI buttons, the camera moves up/down (some kind of a zoom) and at the same time it is rotated from X=90 to X=50 and back again. The problem is that I can’t clamp this range of rotation properly.
Here is what I have:
function Update()
{
transform.localPosition = Vector3( 0, Mathf.Clamp(transform.localPosition.y, MinY, MaxY), Mathf.Clamp(transform.localPosition.z, MinZ, MaxZ));
transform.eulerAngles = Vector3(Mathf.Clamp(transform.eulerAngles.x, 50.0, 90.0), 0, 0);
}
function OnGUI()
{
var movement = new Vector3( 0, -60, 27);
if (GUI.RepeatButton(Rect(ButZIposX,ButZIposY,ButZIwidth,ButZIheight), "Zoom In"))
{
transform.Translate(movement * Speed * Time.deltaTime);
transform.Rotate(Vector3(-1,0,0) * Time.deltaTime);
}
if (GUI.RepeatButton(Rect(ButZOposX,ButZOposY,ButZOwidth,ButZOheight), "Zoom Out"))
{
transform.Translate(movement * -Speed * Time.deltaTime);
transform.Rotate(Vector3.right * Time.deltaTime);
}
}
Is there any suggestions?