Camera's Zoom angle code:
public Transform target;
public float Minfov = 15f;
public float Maxfov = 70f;
public float sensitivity = 10f;
void Start ()
{
Transform. LookAt (target);
}
void Update ()
{
if (Input.getkey (Keycode.leftcontrol) | | Input.getkey (Keycode.rightcontrol))
{
float FOV = Camera.main.fieldOfView;
FOV-= Input.getaxis ("Mouse scrollwheel") * sensitivity;
FoV = Mathf.clamp (FoV, Minfov, Maxfov);
Camera.main.fieldOfView = FOV;
}
}
Mainly by controlling the camera's Fieldofview property, you can adjust your view in the scene.
By judging if the selected object is a target object, rotate it if it is
Code:
Public Transform target;//target object
public float horizontalspeed = 10f;
public float verticalspeed = 10f;
String rotatedirection = null;//determines the current direction of rotation, which is used to fix the current direction of rotation, without allowing the user to rotate vertically when rotated horizontally, or vice versa.
BOOL Istarget = false;//Determines whether the object that the current ray is colliding with is the target object
int rotatestate = 0;//Current rotation state 0 not rotated, 1 constant rotation
Gameobject paneltooltips;
void Start () {
if (!target)
{
target=gameobject.transform;//If Target does not exist, set the object attached to the script as target
}
}
void Update () {
if (Input.getmousebutton (0))
{
if (istarget)//Determine whether the target object is currently selected
{
Rotatestate = 1;
Rotatetarget (target);
}
}
if (input.getmousebuttonup (0))
{
Rotatedirection = null;
Istarget = false;//When the mouse is lifted, set the current object is not the target object
rotatestate = 0;
}
if (Input.getmousebuttondown (0))//each time you press the left mouse button to detect the collision of the object is what
{
Ray ();
}
}
<summary>
Rotational constant Speed object method//
</summary>
<param name= "Transformobj" > Target object to rotate </param>
void Rotatetarget (Transform transformobj)
{
Float h = input.getaxis ("Mouse X");//Right positive left negative
Float v = input.getaxis ("Mouse Y");//Positive negative
if ((Mathf.abs (h) > Mathf.abs (v)) && (rotatedirection! = "Down" && rotatedirection! = "Up"))//Set here when the object is cross Rotation can not be rotated vertically, vertical rotation can not be rotated horizontally, if not required, can be removed after &&, rotatedirection variable can also be deleted
{
if (H < 0)
{
Transformobj.rotate (Vector3.up, horizontalspeed);
Rotatedirection = "Left";
}
else if (H > 0)
{
Transformobj.rotate (-vector3.up, horizontalspeed);
Rotatedirection = "right";//current direction of rotation
}
Rotatestate = 1;//constant rotation
}
else if ((Mathf.abs (h) < Mathf.abs (v)) && (rotatedirection! = "Left" && rotatedirection! = "Right"))// On
{
if (v < 0)
{
Transformobj.rotatearound (Target.transform.position, Vector3.left, verticalspeed);
Rotatedirection = "down";//current direction of rotation is down
}
else if (V > 0)