How to get size of parent game object?

Viewed 24835

I have three child game objects(as you can see in below picture with Red, Pink & Blue). They are child of parent game object Green.

I don't know, how to calculate size of Parent(Green) GameObject?

I am creating all these game objects at runtime using this code:

GameObject CreatePattern(int difficultyLevel)    
    {    
        GameObject gameObjectTemp = new GameObject();    
        SinglePattern singlePattern;    
        gameObjectTemp = (GameObject) Instantiate(gameObjectTemp);   


        singlePattern = freeRunDataHandler.GetSinglePatternRandom(1);    
        GameObject gameObjectSingleObject = null;    
        foreach (SingleObject singleObject in singlePattern.singleObjectList)    
        {
                gameObjectSingleObject = GetGameObjectByCategory(singleObject.catergory, singleObject.type);

            if (gameObjectSingleObject != null)    
            {    
                gameObjectSingleObject = (GameObject) Instantiate(gameObjectSingleObject, new Vector3(singleObject.positionX, singleObject.positionY, singleObject.positionZ), Quaternion.identity);    
                gameObjectSingleObject.transform.localScale = new Vector3(singleObject.length, 1, singleObject.width);    
                gameObjectSingleObject.transform.parent = gameObjectTemp.transform;    
            }    
        }        

        return gameObjectTemp;    
    }

This function returns parent(Green) gameObject after adding all childs. My Parent(Green) have nothing attached to it not even any component(BoxCollider, MeshFilter, MeshRenderer, etc..).

I had attached BoxCollider, MeshRenderer & MeshFilter(Just for testing) & i tried on parent:

parent.collider.bounds.size.x  ----- > box collider
parent.renderer.bounds.size.x  ----- > mesh renderer

But nothing works. There return 1 or zero in cases. Please help me in how to get size of Parent(Green) GameObject?

enter image description here

2 Answers
Related