transform.localscale.set does not work

Hello,

I am instantiating a plane that should serve as the playing field for my game. Because I want to specify its size in the menue, I need to alter it depending on that specification. Therefore I instantiate it and later change its size according to an integer variable called m_dimension. Unfortunately, the plane does not change size, no matter what I enter as dimension.

Here is the code:

m_World[0] = Instantiate(m_Plane, new Vector3(-50f, 0f, -50f), Quaternion.Euler(new Vector3(0f, 0f, 0f))) as GameObject;
        m_World[0].transform.localScale.Set(m_dimension,1,m_dimension);

What did I do wrong?

transform.localScale returns a copy of the scale, so any modifications you do to it will just modify the copy, not the transform’s scale.

To do what you want, store the scale to a variable, change that, and apply it to the transform:

Vector3 scale = m_World[0].transform.localScale;
scale.Set(m_dimension, 1, m_dimension);
m_World[0].transform.localScale = scale;
11 Likes

Great! Thanks, that works!!

its always great this posts are maintained… just helped me out as well :sunglasses: