using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveWithMouse : MonoBehaviour
{
    public float maxX = 10f;
    public float maxZ = 10f;

    void Update()
    {
        var mousePos = Input.mousePosition;
        var newX = map(mousePos.x, 0, Screen.width, -maxX, maxX);
        var newZ = map(mousePos.y, 0, Screen.height, -maxZ, maxZ);

        transform.position = new Vector3(newX, 0, newZ);
    }

    private float map(float value, float fromLow, float fromHigh, float toLow, float toHigh)
    {
        return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
    }
}
