“OnCollision, create a new empty and group the colliding, and collided objects into it.”
I have a game object with a child object. The child (clamp) detects collision.
I clone that object
When the child object detects collision (of another clone of same thing), I want it to:
- create a new empty game object as a ‘group’.
- place the parent objects (transforms) of this object and the one touched into that group. That way they’ll both be children of that new Group object.
I can’t seem to get this working.
#pragma strict
var clamped:boolean = false;
var parentScript:DragDrop;
var coreParent:Transform;
function Start () {
parentScript = this.transform.parent.GetComponent(DragDrop);
coreParent = this.transform.parent;
}
function OnTriggerEnter(col:Collider){
if(col.CompareTag("clamp")) //if tags are matching
{
if(clamped == false && parentScript.selected == true)
{
var group:GameObject = new GameObject(); //create group
coreParent = group.transform;//put self into group
col.gameObject.transform.parent = group.transform;//put collider parent obj into group
}
clamped = true; //do this last to lock it.
}
}