Get Parent Game Object C#

Been looking through the forums and the scripting manual but cant figure this out

I have a house game object and i have a letterbox game object attached under it in the scene hierarchy.

How do I get the house from the letterbox script?

or Transform.root

Hi cjcurrie,

Thanks, solved with your help. Thought transform would only get a transform object but it has a GetComponent method as well.

Rob

1 Like
public Vector3 GetGuiPosition(float yOffset = 0.01f)
    {
        Vector3 v;

        v = Camera.main.WorldToScreenPoint(gameObject.transform.root.position);
        v.x /= Screen.width;
        v.y /= Screen.height;
        v.y += yOffset;
    
        return v;
    }

This is an old thread - But i was trying so hard to understand GUIText and getting a parented guitext to show up correctly. with cj.currie’s help I put together a function that will correct the guitext parented to a single object.

posting code in case someone else stumbles across the same headache

1 Like