I have added Cube to scene and I scaled and put to position ( 0, 0, 0 ). I am scaling that Cube with code attached to Cube
IEnumerator Start() {
StartCoroutine("DoSomething", 2.0F);
yield return new WaitForSeconds(1);
StopCoroutine("DoSomething");
}
IEnumerator DoSomething(float someParameter) {
while (true) {
transform.localScale += new Vector3(0, 0.1f, 0);
yield return null;
}
}
but Cube scales on both sides, to top and bottom. I want to scale with same factor but that bottom of Cube stays on same position.
I tried to set new position between transform.localScale += new Vector3(0, 0.1f, 0);
and yield return null;
but I don't know how to get exact amount.
( I tried to read
Mesh planeMesh = gameObject.GetComponent<MeshFilter>().mesh;
Bounds bounds = planeMesh.bounds;
bounds.size.y;
before and after scale and add to
transform.position.y
difference between
boundsAfter.size.y
and boundsBefore.size.y
but it moves too much.
How to solve this ?