Пример #1
0
 /// <summary>
 /// Attaches the camera system to the agent
 /// </summary>
 void AttachAgent()
 {
     if (_toggle.isOn)
     {
         cameraBehaviour.AttachToCharacter(character);
     }
     else
     {
         cameraBehaviour.Detach();
     }
 }
    void Update()
    {
        if (!detached)
        {
            if (attachedCharacter == null)
            {
                detached = true;
            }
            else
            {
                transform.position = attachedCharacter.transform.position;
            }
        }

        // Move the camera with the middle mouse button
        if (Input.GetKey(KeyCode.Mouse2))
        {
            if (!detached)
            {
                _cameraBehaviour.Detach();
                detached = true;
            }

            Vector3 cameraAngle = _transform.eulerAngles;
            cameraAngle.x = 0; //Makes sure we dont zoom in
            var direction = Quaternion.Euler(cameraAngle) * Vector3.right * -Input.GetAxis("Mouse X");
            direction           += Quaternion.Euler(cameraAngle) * Vector3.forward * -Input.GetAxis("Mouse Y");
            _transform.position += direction * movementSpeed;
        }

        // Scroll zoom
        float zoom = Mathf.Clamp(offset.localPosition.z + Input.mouseScrollDelta.y, -maxZoom, -minZoom);

        offset.localPosition = Vector3.forward * zoom;

        // Right click to rotate
        if (Input.GetMouseButton(1))
        {
            // Rotate around the y-axis.
            _transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * rotateSpeed);

            // Rotate around the local x-axis, clamp this rotation in between specified angles.
            float angle = Mathf.Clamp(xAxis.rotation.eulerAngles.x - Input.GetAxis("Mouse Y") * rotateSpeed, minRotationY, maxRotationY);
            xAxis.localRotation = Quaternion.AngleAxis(angle, Vector3.right);
        }
    }