Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit)

This is a really good idea! Thanks!
The implementation contains some nuances:

Input.mousePosition return pixel coordinates. It needs to be converted to virtual coordinates.

// Moving player to left and right
void MovePlayer()
{
    // Get mouse position in pixel-coordinate system and transform it to virtual-coordinate system
    Ray mouseRay = camera.ScreenPointToRay(Input.mousePosition);
    mouseX = mouseRay.GetPoint(10f).x;
    if (gameManager.isGameActive)
    {
        if (mouseX < leftBound)
        {
            positionX = leftBound;
        }
        else if (mouseX > rightBound)
        {
            positionX = rightBound;
        }
        else
        {
            positionX = mouseX;
        }
        playerRb.MovePosition(new Vector3(positionX, playerPosY, playerPosZ));
    }
}

The project has updated. You can test it.

Added a link to you in devlog ;)