- Home /
Question by
zmirkovich · Aug 10, 2018 at 11:53 PM ·
scalingtouch controls
How to keep GUI's shape while scaling on both X & Y axis with max/min values,How to keep GUI's initial shape while scaling
Been working on the UI of an application with panels that scroll both horizontally and vertically. In order to access the vertical component the panel must first fill the screen. I'm having trouble keeping the panels shape (rectangle) while scaling both the X and Y components as I am scaling as the user swipes up. In addition, I need the panel to only stretch to the edges and fill the screen, but it keeps growing past it. The code is attached bellow.
public float sizingFactor = 0.005f;
private float startSize;
private float startY;
private float startX;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
startY = position.y;
startX = position.x;
position = Camera.main.ScreenToWorldPoint(position);
startSize = transform.localScale.x;
}
if (Input.GetMouseButton(0))
{
Vector3 size = transform.localScale;
size.y = startSize + (Input.mousePosition.y - startY) * sizingFactor;
size.x = startSize + (Input.mousePosition.x - startX) * sizingFactor;
transform.localScale = size;
}
}
}
Comment