# how to limit scale to 1 to avoid negative scaling.

A gameobject scales with following code, but i want to limit to min scale of 1, because it becomes zero and goes into negative scaling, which i dont want.
how do i modify the code to make that work.

function Update()
{
if (Input.GetKey (“[-]”))
{
transform.localScale -= Vector3(1,1,1) ;
}
if (Input.GetKey (“[+]”))
{
transform.localScale += Vector3(1,1,1);
}
}

if (transform.localScale.y < 1) transform.localScale = Vector3.one;

Consider using a uniform scale (on each axis) to make it work properly or do it on each axis.

i did it like this and it worked

`````` function Update()

{

if (Input.GetKey ("[-]"))

{
transform.localScale -= Vector3(1,1,1) ;
transform.localScale.x = Mathf.Clamp(transform.localScale.x, 5, 500);
transform.localScale.y = Mathf.Clamp(transform.localScale.y, 5, 500);
transform.localScale.z = Mathf.Clamp(transform.localScale.z, 5, 500);

}

if (Input.GetKey ("[+]"))
{
transform.localScale += Vector3(1,1,1);
transform.localScale.x = Mathf.Clamp(transform.localScale.x, 5, 500);
transform.localScale.y = Mathf.Clamp(transform.localScale.y, 5, 500);
transform.localScale.z = Mathf.Clamp(transform.localScale.z, 5, 500);

}
}
``````