Esempio n. 1
0
    void Movement()

    {
        // Local variable to hold the camera target's position during each frame

        Vector3 pos = transform.position;

        // Local variable to reference the direction the camera is facing (Which is driven by the Camera target's rotation)

        Vector3 forward = transform.forward;

        // Ensure the camera target doesn't move up and down

        forward.y = 0;

        // Normalize the X, Y & Z properties of the forward vector to ensure they are between 0 & 1

        forward.Normalize();


        // Local variable to reference the direction the camera is facing + 90 clockwise degrees (Which is driven by the Camera target's rotation)

        Vector3 right = transform.right;

        // Ensure the camera target doesn't move up and down

        right.y = 0;

        // Normalize the X, Y & Z properties of the right vector to ensure they are between 0 & 1

        right.Normalize();


        // Move the camera (camera_target) Forward relative to current rotation if "W" is pressed or if the mouse moves within the borderWidth distance from the top edge of the screen

        if (Input.GetKey("w") || edgeScrolling == true && Input.mousePosition.y >= Screen.height - borderWidth)

        {
            pos += forward * panSpeed * Time.deltaTime;
        }


        // Move the camera (camera_target) Backward relative to current rotation if "S" is pressed or if the mouse moves within the borderWidth distance from the bottom edge of the screen

        if (Input.GetKey("s") || (edgeScrolling == true && Input.mousePosition.y <= borderWidth))

        {
            pos -= forward * panSpeed * Time.deltaTime;
        }


        // Move the camera (camera_target) Right relative to current rotation if "D" is pressed or if the mouse moves within the borderWidth distance from the right edge of the screen

        if (Input.GetKey("d") || (edgeScrolling == true && Input.mousePosition.x >= Screen.width - borderWidth))

        {
            pos += right * panSpeed * Time.deltaTime;
        }


        // Move the camera (camera_target) Left relative to current rotation if "A" is pressed or if the mouse moves within the borderWidth distance from the left edge of the screen

        if (Input.GetKey("a") || (edgeScrolling == true && Input.mousePosition.x <= borderWidth))

        {
            pos -= right * panSpeed * Time.deltaTime;
        }


        // Setting the camera target's position to the modified pos variable
        var old = transform.position;

        if (old != pos)
        {
            transform.position = pos;
            ClientEvents.CameraMove(transform.position, pos);
        }
    }