A error about Mathf.Clamp


VS said Cannot implicitly convert type ‘float’ to ‘UnityEngine.Vector2’
where is my problem?

paddlePos is not a float, so it can’t assign the result of the expression to it.

So you want to create a new vector2 where the x position is set to your clamped result, instead of the entire vector (both an x and a y).

You could either (amongst other choices):

Set:
paddlePos.x = Mathf.Clamp(…);

Or:
float newX = Mathf.Clamp(…);
Vector2 paddlePos = new Vector2(newX, transform.position.y);

Something like that, so that your right-hand expression will fit in your left-hand variable.

1 Like

now works ,thank you

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms