How can I scale my object in one direction???

Hey Everyone,

I’ve searched a lot but couldn’t find what I want…

when I drag my mouse left for scaling my object but the object become wider from both sides and I only want it in on direction…

Is there any sample way to scale the object on one direction???

Try this: make an empty GameObject, and add the one you want to scale as a child of it. move the inner object to position 0,0,0. then move the inner object such that the center of the parent object is at the edge of the inner object (in your case, the right edge). Now resize the outer GameObject as needed. Before you try to apply this, reset the scaling and position of your object, that should make this easier.

Hi everyone!

For anyone wondering how to scale an object in a specific direction, this little function maybe helpful.

public void Resize(float amount, Vector3 direction)
{
     transform.position += direction * amount / 2; // Move the object in the direction of scaling, so that the corner on ther side stays in place
     transform.localScale += direction * amount; // Scale object in the specified direction
}

Usage :
If you want to scale a platform in z direction by 5 units, then

Resize(5f, new Vector3(0f, 0f, 1f); // You can use Vector3.forward instead

That’s it. Enjoy, Have a nice day!

You should change your pivot to FI “top-left”. Depends on what kind of object, but normally pivot is set to center as default.

If anyone needs to revert object to the old size here:

   void Update()
    {
        if (Input.GetMouseButtonDown(0))//LeftMouseButton
        {
            IncreaseObjectSize(5f, new Vector3(0f, 0f, 1f));
        }
        else if (Input.GetMouseButtonDown(1))//RightMouseButton
        {
            DecreaseObjectSize(5f, new Vector3(0f, 0f, 1f));
        }
    }
    public void IncreaseObjectSize(float amount, Vector3 direction)
    {
        transform.position += direction * amount / 2; // Move the object in the direction of scaling, so that the corner on ther side stays in place
        transform.localScale += direction * amount; // Scale object in the specified direction
    }
    public void DecreaseObjectSize(float amount, Vector3 direction)
    {
        transform.position -= direction * amount / 2;
        transform.localScale -= direction * amount;
    }