// create a child GameObject and add a trigger to it to do the intersection detection private void ConstructTrigger() { var go = new GameObject(); go.name = "IntersectionTrigger"; // attach it to this block and make it exactly the same, except slightly smaller go.transform.parent = transform; go.transform.localPosition = Vector3.zero; //exactly at the centre of the actual object go.transform.localScale = 0.9f * Vector3.one; //slightly smaller than the actual object go.transform.localRotation = Quaternion.identity; // same rotation as the actual object // add the same type of collider as the block has and make it a trigger var col = (Collider)go.AddComponent(GetComponent <Collider>().GetType()); col.isTrigger = true; // attach the script to the collider and connect it to this script IntersectionTrigger script = go.AddComponent <IntersectionTrigger>(); script.SetSnappingScript(this); }
private void ConstructTrigger() { GameObject go = new GameObject("IntersectionTrigger"); go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; go.transform.localRotation = Quaternion.identity; BoxCollider blockCol = GetComponent <BoxCollider>(); BoxCollider IntersectionCol = go.AddComponent <BoxCollider>(); IntersectionCol.size = blockCol.size; IntersectionCol.center = blockCol.center; IntersectionCol.isTrigger = true; IntersectionTrigger script = go.AddComponent <IntersectionTrigger>(); script.SetSnappingScript(this); }