void AttachToFixid() { // List 型で追従先の子孫オブジェクトを取得 toFixidList = GetAllChildren.GetAll(toFixid); int i = 0; foreach (GameObject obj in toFixidList) { // ループで追従先にRigidbody をアタッチ Rigidbody rb = obj.GetComponent <Rigidbody>(); if (rb == null) { rb = obj.AddComponent <Rigidbody>(); } rb.angularDrag = 0; rb.useGravity = false; rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ; // ループで追従先に FixidJoint をアタッチ FixedJoint fj = obj.AddComponent <FixedJoint>(); // 適切な追従元を追従先のconnected body にアタッチ GameObject fromBody = fromList[i]; fj.connectedBody = fromBody.GetComponent <Rigidbody>(); i++; } }
void AttachFrom() { // List 型で本体の子孫オブジェクトを取得 fromList = GetAllChildren.GetAll(from); foreach (GameObject obj in fromList) { // ループで本体の子孫オブジェクトに Rigidbody をアタッチ Rigidbody rb = obj.AddComponent <Rigidbody>(); rb.angularDrag = 0; rb.useGravity = false; rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; } }