Thursday, 15 July 2010

unity3d - Canvas Screen Scaling with script Instantiated objects? -


Can anyone explain to me when my immediate shop UI looks amazing in the editor (left), but while walking on the device (Right), it looks trivial ?, so do it (please excuse the tight cam picture!):

UI bars prefabs , In which the canvas for individual and various UI elements for scaling With the reference resolution set to width in width, set to X: 320 Y: 480, each screen is set manually for scaling. This has proven to work brilliantly in my previous games, but it does not catch anyone. I have manually set the properties of each institutionalized object for scaling in scripts, but still nothing.

The only thing that I am distinguishing the UI is making the prefabs immediately on the runtime when filling them when the shop is made.

Has anyone seen this before? How to fix it?

When you instantiate the prefab in the code, and then you have given that prefab some parents, unity u The system tries to understand the difference between the size of a prefab when it was made and it should be shaped after the canvas scalar update.

When I do something like this in my code, expansion:

  Public Fixed Zero SetParentAndReset (This RectTransform rect, parent origin) {rect.SetParent (parent); Rect.localScale = Vector3.one; Rect.localPosition = Vector3.zero; } ... var newObj = Institute (prefab); Var rect = newObj.GetComponent & lt; RectTransform & gt; (); Rect.SetParentAndReset (parent); Rect.localPosition = new vector 3 (1f, 1f, 1f); // real status  

No comments:

Post a Comment