# Constraint on localScale - how to?

Hello,

Im looking to contrain the local scale of my 2d box, i’ll post code below, but in text form, i have a 2D box, controlled by the arrows keys, UP makes it go up, RIGHT goes right etc and when the space bar is held, the arrow keys change the size of the box instead of position, i.e up increase height, down decreases, reight increases width, left decrease.

But when space bar is held and you decrease the box until it hits a zero value, it flips and instead of the left button decsreasing width, its incresaing the width of the box in the opposite direction. Can i contraint this so that when the box hits its minimum value of zero it doesnt flip and start increasing the other way.

This code is for localscale only.

Code follows.

``````using UnityEngine;
using System.Collections;

public class localScale : MonoBehaviour {

void Start ()
{
}

void Update ()
{

if (Input.GetKey (KeyCode.Space))
{
if (Input.GetKey (KeyCode.RightArrow))
{
transform.localScale += new Vector3(0.05f,0.0f,0);

}
}
if (Input.GetKey (KeyCode.Space))
{
if (Input.GetKey (KeyCode.LeftArrow))
{
transform.localScale -= new Vector3(0.05f,0.0f, 0 );
}
}

if (Input.GetKey (KeyCode.Space))
{
if (Input.GetKey (KeyCode.DownArrow))
{
transform.localScale -= new Vector3 (0.0f,0.05f, 0);
}
}

if (Input.GetKey (KeyCode.Space))
{

if (Input.GetKey (KeyCode.UpArrow))
{
transform.localScale += new Vector3(0.0f,0.05f, 0 );

}

}
}
}
``````

Very simple

``````void Update ()
{
if (Input.GetKey (KeyCode.Space))
{
if (Input.GetKey (KeyCode.RightArrow))
{
transform.localScale += new Vector3(0.05f,0.0f,0);
}

if (Input.GetKey (KeyCode.LeftArrow) && transform.localScale.x > 0.0f)
{
transform.localScale -= new Vector3(0.05f,0.0f, 0 );
}

if (Input.GetKey (KeyCode.DownArrow) && transform.localScale.y > 0.0f)
{
transform.localScale -= new Vector3 (0.0f,0.05f, 0);
}

if (Input.GetKey (KeyCode.UpArrow))
{
transform.localScale += new Vector3(0.0f,0.05f, 0 );
}
}
}
``````