if (Input.getkey (KEYCODE.Q))
{
Transform. Rotate (0,-50*time.deltatime,0,space.self);
}
if (Input.getkey (KEYCODE.E))
{
Transform. Rotate (0,50*time.deltatime,0,space.self);
}
Mimic WOW lens operation
- Using Unityengine;
- Using System.Collections;
- ///
- Attaching this script to any lens allows it to have a WOW lens control
- ///
- public class Wowcamera:monobehaviour
- {
- ///
- Lens target
- ///
- Public Transform Target;
- ///
- The distance of the lens from the target
- ///
- public float Distance = 30.0f;
- ///
- Maximum Lens distance
- ///
- public float maxdistance = 30.0f;
- ///
- The mouse wheel pulls the far speed coefficient
- ///
- public float scrollfactor = 10.0f;
- ///
- Lens Rotation speed ratio
- ///
- public float rotatefactor = 10.0f;
- ///
- Lens horizontal Surround Angle
- ///
- public float horizontalangle = 45;
- ///
- Lens vertical Surround Angle
- ///
- public float verticalangle = 0;
- Private Transform Mcameratransform;
- void Start ()
- {
- Mcameratransform = transform;
- }
- void Update ()
- {
- Wheel forward: close the distance; Roller back: Pull Away
- var scrollamount = Input.getaxis (Gamesetting.mousescrollwheel);
- Distance-= ScrollAmount * Scrollfactor;
- Ensure lens distance is legal
- if (Distance < 0)
- Distance = 0;
- else if (Distance > MaxDistance)
- Distance = maxdistance;
- Press and hold the mouse button to move, the lens rotates with it
- var ismouseleftbuttondown = Input.getmousebutton (0);
- var ismouserightbuttondown = Input.getmousebutton (1);
- if (Ismouseleftbuttondown | | ismouserightbuttondown)
- {
- Screen.lockcursor = true;
- var AxisX = Input.getaxis (gamesetting.mousex);
- var axisy = Input.getaxis (Gamesetting.mousey);
- Horizontalangle + = AxisX * Rotatefactor;
- Verticalangle + = Axisy * Rotatefactor;
- if (Ismouserightbuttondown)
- {
- If the right mouse button is moved, the rotated character is aligned on the horizontal plane with the lens orientation
- target.rotation = Quaternion.euler (0, Horizontalangle, 0);
- }
- }
- Else
- {
- Screen.lockcursor = false;
- }
- Adjust position and orientation by lens distance
- var rotation = Quaternion.euler (-verticalangle, Horizontalangle, 0);
- var offset = rotation * Vector3.back * Distance;
- Mcameratransform.position = target.position + offset;
- Mcameratransform.rotation = rotation;
- }
- }
Unity3d Learning Tutorial C # Rotating Lens