- Home /
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?
The child objects in the prefab are scaled differently. But when i scale the parent in editor all looks fine ...
Answer by ArmarageX · Jun 25, 2015 at 07:13 AM
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?
Your answer
Follow this Question
Related Questions
Scaling GUI correctly according to game window resolution? 1 Answer
Game screen scale 2 Answers
Best way to downsample camera viewport? 1 Answer
Same enemies per row across all mobile resolutions 1 Answer
Shadow quality and small object scale? 3 Answers