void Start() { int numSpheres = 2 * 15; //(int)(Random.Range(1, 5)); spheres = new GameObject[numSpheres]; for (int i = 0; i < numSpheres; i++) { spheres[i] = (GameObject)Instantiate(sphere_prefab, new Vector3(Random.value * 10, Random.value * 10, Random.value * 10), Quaternion.identity); } bones = new GameObject[numSpheres - 1]; for (int i = 0; i < bones.Length; i++) { // Store the clone of the bone prefab in an array bones[i] = (GameObject)Instantiate(bone_prefab, Vector3.zero, Quaternion.identity); // Add the joints by getting the script as a component BoneScript script = bones[i].GetComponent("BoneScript") as BoneScript; script.joint1 = spheres[i]; script.joint2 = spheres[i + 1]; script.radius = 0.5f; } pos = new Vector3[numSpheres]; targets = new Vector3[numSpheres]; t = 1; }
void OnTriggerEnter(Collider other) { script = other.gameObject.GetComponent<BoneScript> (); int otherID = script.BoneID; if (otherID != BoneID) { int beforeID = BoneID - 1; int afterID = BoneID + 1; if(otherID != beforeID && otherID != afterID){ //부모 오브젝트의 충돌 여부를 알림 Debug.Log ("["+BoneID+"]"+" "+otherID); this.GetComponentInParent<SocketClient>().CollisionDetected(); this.GetComponent<Renderer>().material.color = Color.red; } } }
private GameObject addBone(String name, float radius, GameObject prefab, Transform body, Kinect.JointType joint1, Kinect.JointType joint2 = null) { GameObject bone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity); bone.name = name; bone.transform.parent = body; BoneScript script = bone.getComponent("BoneScript") as BoneScript; script.radius = radius; script.joint1 = body.FindChild(joint1.ToString()).gameObject; if (joint2 != null) { script.joint2 = body.FindChild(joint2.ToString()).gameObject; } else if (_BoneMap.ContainsKey(joint1)) { script.joint2 = body.FindChild(_BoneMap [joint1].ToString()).gameObject; } else { Debug.LogError("BAD JOINT: " + joint1); } return(bone); }