Exemple #1
0
        private void LateUpdate()
        {
            canRotate = !GetComponent <Camera>().orthographic;
            canMove   = GlobalManager.Instance.CanCameraMove(this);
            if (canMove)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    BeginMoveCam();
                }

                if (Input.GetMouseButton(1))
                {
                    if (!startMoving)
                    {
                        BeginMoveCam();
                    }
                    prevMousePos = mousePos;
                    mousePos     = Input.mousePosition;
                }

                if (Input.GetMouseButtonUp(1))
                {
                    EndMoveCam();
                }
                MoveWithArrows();
            }
            else
            {
                EndMoveCam();
            }

            if (Input.GetMouseButton(2) && canRotate && canMove)
            {
                xDeg += Input.GetAxis("Mouse X") * Speed * 0.02f;
                yDeg -= Input.GetAxis("Mouse Y") * Speed * 0.02f;

                yDeg = VectorFunctions.ClampAngle(yDeg, yMinLimit, yMaxLimit);

                desiredRotation = Quaternion.Euler(yDeg, xDeg, 0.0f);
                currentRotation = transform.rotation;

                rotation           = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
                transform.rotation = rotation;
            }

            if (canMove)
            {
                position += transform.forward * Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * moveSpeed;
                if (mousePos - prevMousePos != Vector3.zero)
                {
                    position += transform.rotation * (mousePos - prevMousePos) * -1 * Time.deltaTime * moveSpeed;
                }
            }

            position += Forcedpos;

            var x = Mathf.Clamp(position.x, minBound.x, maxBound.x);
            var y = Mathf.Clamp(position.y, minBound.y, maxBound.y);
            var z = Mathf.Clamp(position.z, minBound.z, maxBound.z);

            if (float.IsNaN(x))
            {
                x = 0;
            }
            if (float.IsNaN(y))
            {
                y = 0;
            }
            if (float.IsNaN(z))
            {
                z = 0;
            }

            position = new Vector3(x, y, z);

            transform.position = new Vector3(x, y, z);
        }