public class PaddleMove : MonoBehaviour
{
[SerializeField] float gameUnitWidth = 16f;
[SerializeField] float xMinOffset = 14.66f;
[SerializeField] float xMaxOffset = 1.34f;
void Start()
{
}
void Update()
{
float xCalcUnits = Screen.width / Screen.width * gameUnitWidth;
// had an interesting bug fix here ^^ where the paddle was not on the screen because without "Screen.width / Screen.width" the position got all messed up, due to you know "math"
float xMin = (xCalcUnits - xMinOffset);
float xMax = (xCalcUnits - xMaxOffset);
float xPos = Input.mousePosition.x / Screen.width * gameUnitWidth;
Debug.Log(Input.mousePosition.x / Screen.width * gameUnitWidth);
float mousePaddleXInUnits = Mathf.Clamp(xPos, xMin, xMax);
Vector2 paddlePosition = new Vector2(mousePaddleXInUnits, transform.position.y);
transform.position = paddlePosition;
}
}