void Update()
{
if (Input.GetMouseButton(1))
{
AngleY += Input.GetAxis("Mouse X") * sensitivityX;
}
Distance -= Input.GetAxis("Mouse ScrollWheel") * 10f;
AngleX -= Input.GetAxis("Mouse ScrollWheel") * 20f;
if (AngleX < MinXRotation)
{
AngleX = MinXRotation;
}
if (AngleX > MaxXRotation)
{
AngleX = MaxXRotation;
}
if (Distance < MinDistance)
{
Distance = MinDistance;
}
if (Distance > MaxDistance)
{
Distance = MaxDistance;
}
Quaternion rotation = Quaternion.Euler(AngleX, AngleY, 0);
transform.rotation = rotation;
transform.position = target.position + rotation * new Vector3(0, 0, -Distance) + noise;
}