Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

World space UI scale independent of parent

Discussion in 'VR' started by barmyard, Nov 15, 2016.

  1. barmyard


    Oct 6, 2016
    Hi All,

    I have a FBX model with several submeshes(they are children of the root model GameObject).
    I want to be able to select such a submesh and project a menu behind the selected submesh (much like 3D viewer beta's menu).
    The menu always has to have the same size. However, some of my submeshes have a scale of 100, other have a scale of 3. The result is that the menu behind the selected submesh changes in size depending on the scale of the selected submesh.
    I am new to Unity, but understand that the scale depends on the parent, so I I try to work around the scale behaviour by first storing the originial scale in a tmp and resetting localScale after setting the parent, but this doesn't work.
    Here is the code for toggling the menu:
    Code (CSharp):
    2. public void ToggleMenu(GameObject SelectedObject)
    3.     {
    4.         if (SelectedObject.transform.childCount == 0)
    5.         {
    6.             GameObject menu = Instantiate(Resources.Load("MyCanvas")) as GameObject;
    7.             Vector3 tmpScale = menu.transform.localScale;
    8.             menu.transform.SetParent(SelectedObject.transform, false);
    9.             menu.transform.localScale = tmpScale;
    10.         }
    11.         else // Has menu attached, delete
    12.         {
    13.             Destroy(SelectedObject.transform.GetChild(0).gameObject);
    14.         }
    15.     }
    Any ideas? Cheers
  2. KarlosZafra


    Sep 8, 2016
    You could create parents with scale 1 for each of the children with custom scales, and then update the scale on those.

    And you should try posting in other areas of the forum more related with the topic, this not related with HoloLens at all.