- Home /
Question by
Magistrix · Nov 14, 2011 at 09:19 PM ·
encapsulation
Use "Encapsulate" to encapsulate objects children
I’ve got a big issue with using the encapsulate function… I want a cube to encapsulate multiple child’s of another more complex 3d model to create something like a big encapsulating bounding box around this complex 3d model automatically. In the uniy3D manual is written only few about this function:
function Encapsulate (point : Vector3) : void Description Grows the Bounds to include the point. function Encapsulate (bounds : Bounds) : void Description Grow the bounds to encapsulate the bounds. I’ve tried out different things to get my cube automatically scaled to the correct size…but without any results. So far I’ve written the following code: using UnityEngine; using System.Collections;Bounds.Encapsulate
public class _boundingCreator : MonoBehaviour { public string s_affectedTag = "MovableObject"; public GameObject go_defaultBoundingBox; GameObject[] go_affectedObjects;
void Start() { go_affectedObjects = GameObject.FindGameObjectsWithTag(s_affectedTag); m_encapsulateObject(); }
void m_encapsulateObject() { foreach(GameObject go_object in go_affectedObjects) { GameObject go_box = Instantiate(go_defaultBoundingBox,go_object.transform.position,go_defaultBoundingBox.transform.rotation) as GameObject; go_object.transform.parent = go_box.transform;
Transform[] go_childObjects = go_object.GetComponentsInChildren(); foreach(Transform child in go_childObjects) { if(child.transform.renderer != null) { go_box.transform.renderer.bounds.Encapsulate(child.transform.renderer.bounds); print(child.name); } } } } } The game object I wish to encapsulate has been found by this script (all child’s where printed by the “print” statement) but my cube is not affected by the “encapsulate” in any way :( If would highly appreciate any help or hints how to achieve a working encapsulating script!
Comment
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Events vs GetComponent for inter-script functionality 1 Answer
How to import the object from server to unity 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer