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:
public void ToggleMenu(GameObject SelectedObject)
{
if (SelectedObject.transform.childCount == 0)
{
GameObject menu = Instantiate(Resources.Load("MyCanvas")) as GameObject;
Vector3 tmpScale = menu.transform.localScale;
menu.transform.SetParent(SelectedObject.transform, false);
menu.transform.localScale = tmpScale;
}
else // Has menu attached, delete
{
Destroy(SelectedObject.transform.GetChild(0).gameObject);
}
}
Any ideas? Cheers