// Update is called once per frame
    void Update()
    {
        IMapEditorTool mapEditorTool = toolSelector.toolSelected;

        // Mouse left click
        if (Input.GetMouseButtonDown(0))
        {
            // If the event is responded by UI elements, do not respond again.
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Respond click
            if (mapEditorTool != null)
            {
                mapEditorTool.RespondMouseLeftClick();
            }
            else
            {
                SelectClicked();
            }
        }

        // Mouse left click up
        if (Input.GetMouseButtonUp(0))
        {
            // If the event is responded by UI elements, do not respond again.
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Respond click
            if (mapEditorTool != null)
            {
                mapEditorTool.RespondMouseLeftUp();
            }
        }

        // Mouse right click
        if (Input.GetMouseButtonDown(1))
        {
            // If the event is responded by UI elements, do not respond again.
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Respond click
            if (mapEditorTool != null)
            {
                if (mapEditorTool.CanDestroy())
                {
                    toolSelector.DeselectCurrentTool();
                }
                else
                {
                    mapEditorTool.RespondMouseRightClick();
                }
            }
            else
            {
                DeselectAll();
            }
        }

        // Mouse move
        if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
        {
            if (mapEditorTool != null)
            {
                mapEditorTool.RespondMouseMove(
                    Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
            }
        }
    }