やりたいことですが、onotchi_ (id:onoty3d)さんという方が作成されていたプログラムコードを用いて、生成したCube同士をfixedJointで接続させたいです。
onotchi_ (id:onoty3d)さんのサイト↓
http://onoty3d.hatenablog.com/entry/2017/06/11/190909
やったことなのですが、VoxelGeneratr.cs内のpraibate void SpawnVoxel()のコードに以下のことを追加してみました。
・生成されたCubeにRigidbodyとFixedJointをAddComponent
・cuountでvoxelの個数表示
・生成したときにnameを変える(connectedBodyで名前指定ができると考えたので)
Rigidbody rb;
int count = 0;
int i = 1;
private void SpawnVoxel()
{
var voxel = GameObject.CreatePrimitive(PrimitiveType.Cube);
voxel.layer = (int)Mathf.Log(this.VoxelLayer.value, 2); voxel.transform.position = this._transform.position + this._voxelPosition; voxel.transform.localScale = this._voxelScale; if (count < i) { Debug.Log("Cube" + count); count += 1; i += 1; voxel.name = "Cube" + count; } //重力を設定 rb = voxel.gameObject.AddComponent<Rigidbody>(); rb.isKinematic = true; //結合先を設定 fixedJoint = voxel.AddComponent<FixedJoint>(); fixedJoint.connectedBody =voxel.GetComponent<Rigidbody>(); voxel.transform.SetParent(this.Parent); }
他にもfind(name)など調べ、追加してみたのですがうまくいきませんでした。
Unityが初めてで見当違いなことを言ってしまっていたり、変なコードを記述していたらすいません。
どうかよろしくお願いします。