I am new to using Unity (although my confidence is growing) and I am new to C#. For this project I am working on we are making a side scrolling shooter. Last night i managed to set up my GUI pause menu so it positions itself correctly when the screen resolution changes.
I want to achieve the same thing with my clamping. At the moment I have clamped the player on screen using Mathf.Clamp using this code…
private int minXValue = -8; private int maxXValue = 8; private int minYValue = -3; private int maxYValue = 5; Vector3 pos = transform.position; pos.y = Mathf.Clamp (pos.y, minYValue, maxYValue); pos.x = Mathf.Clamp (pos.x, minXValue, maxXValue); transform.position = pos;
However when the resolution changes naturally the positions I have stated no longer apply (well the Y value works fine). I would like some help to clamp the player to the edge of the screen when the screen resolution changes. Thanks for reading
EDIT - Forgot to mention that the clamping code is inside update.