
I am trying to scale a rectangle on the X axis and keep it's position the same as it was. Normally when you scale sprite or object in Unity3D it's from it's center and expands on both sides of the given axis. What i tried is:
- Scale the object on the X axis with some value.
- Reposition it half the given scaling size back.
When i perform these two steps, somehow i get near the desired result, but the object still expands with some very small amount on the opposite side.
private float m_scaleSize = 1.1600f;
private void Update()
{
transform.localPosition -= new Vector3(0, m_scaleSize / 2, 0) * Time.deltaTime;
transform.localScale += new Vector3(0, m_scaleSize, 0) * Time.deltaTime;
}
Why am i getting almost the correct result? Is this some floating point imprecision or my math is totally wrong? I also want to point out that i am looking for the math solution and achieve this without parenting it to some other object in order to get this effect.