hi, everyone
i am having little prob while zoomin camera using GUIbutton.
can somebody help me ??
here’s code
for my camera
//WASD to orbit, left Ctrl/Alt to zoom
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Keyboard Orbit")]
public class Guikeys : MonoBehaviour {
public Transform target;
public float distance = 20.0f;
public float zoomSpd = 2.0f;
public float xSpeed = 240.0f;
public float ySpeed = 123.0f;
public int yMinLimit = -723;
public int yMaxLimit = 877;
private float x = 0.0f;
private float y = 0.0f;
private float GUIHorizontal = 0;
private float GUIVertical = 0;
public GUIStyle uptexture;
public GUIStyle lefttexture;
public GUIStyle righttexture;
public GUIStyle downtexture;
public GUIStyle Zoomintexture;
public GUIStyle Zoomouttexture;
public GUIStyle reset;
public void Start () {
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
void OnGUI()
{
if(Event.current.type == EventType.Repaint)
{
GUIHorizontal = 0;
GUIVertical = 0;
}
//GUI.Box(new Rect(910,45,106,120),"Camera Control");
//GUI.Box(new Rect(810,175,205,40),"");
GUILayout.BeginVertical();
if(GUI.RepeatButton(new Rect(1130,470,30,30),"",uptexture))
{
GUIVertical = 1;
}
GUILayout.BeginHorizontal();
if(GUI.RepeatButton(new Rect(1100,500, 30, 30),"", lefttexture))
{
GUIHorizontal = -1;
}
if(GUI.RepeatButton(new Rect(1160,500, 30, 30),"", righttexture))
{
GUIHorizontal = 1;
}
GUILayout.EndHorizontal();
if(GUI.RepeatButton(new Rect(1130,530, 30, 30),"", downtexture))
{
GUIVertical = -1;
}
GUILayout.EndVertical();
if(GUI.RepeatButton(new Rect(1130,565, 30, 30),"",Zoomintexture))
{
// i was just trying to press keyboard key via GUIbutton but didn't work.
//Input.GetKeyDown("Plus");
}
if(GUI.RepeatButton(new Rect(1130,600, 30, 30),"",Zoomouttexture))
{
//Input.GetKeyDown("Minus");
// same here
}
if(GUI.RepeatButton(new Rect(1130,50, 30, 30),"",reset))
{
//reset camera;
}
}
public void LateUpdate () {
if (target) {
x -= Input.GetAxis("Horizontal") * xSpeed * 0.02f;
y += Input.GetAxis("Vertical") * ySpeed * 0.02f;
x -= GUIHorizontal * xSpeed * 0.02f;
y += GUIVertical * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
distance -= Input.GetAxis("Fire1") *zoomSpd* 0.02f;
distance += Input.GetAxis("Fire2") *zoomSpd* 0.02f;
Quaternion rotation = Quaternion.Euler(y, x, 0.0f);
Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
public static float ClampAngle (float angle, float min, float max) {
if (angle < -360.0f)
angle += 360.0f;
if (angle > 360.0f)
angle -= 360.0f;
return Mathf.Clamp (angle, min, max);
}
}