How to re-size prefab in code

I have a prefab created by joining several cylinders using hinge joints. I can resize the prefab during design time to any value and it works perfectly in game.

I decide to resize the object in run time based on the screen resolution using following code.

void Awake()
{

	float  screenHeight = Screen.height/2;
		
	int scaleValue = (int)(screenHeight/160);
			
	gameObject.transform.localScale = new Vector3(scaleValue,scaleValue,scaleValue);
}

when i do that cylinders make up the prefab are not in the correct positions. But they are in correct positions if I re-size to the same value in editor.

Can anyone explain why this is happening?

Can anyone provide some help on this?

The child objects in the prefab are scaled differently. But when i scale the parent in editor all looks fine ...

bump .......

Bump......

1 Answer

1

HingeJoints mean rigidBody is happening? See if it scales properly without having rigidBody / Hinge?
Perhaps the physics are interfering with some cached data…
And if so… you may have to dynamically add rigidBody on runtime?