resizing runtime

Hello folks,

I’m resizing an object runtime by setting up assign different Vector3 value to the localScale value as seen below.

UpdateSize()
{
size += intensity * Time.deltaTime; // intensity varies by player’s input
cachedTransform.localScale = new Vector3(size, 1, size);
}

And what i’m seeing is that the app becomes pretty slower when ever the function is called… Is there a better way to implement this? I feel creating a new vector3 each frame is very expensive, but couldn’t find a way around, since x,y,z value of Vector3 is read-only.

Thanks in advance!

I’ve only run into the read-only components on specific vectors built into Unity classes. If you create your own vector variable in the class you should be able to assign x, y, and z directly and then assign that vector to the localScale.

didn’t know that.

Thanks a lot :wink: