void GenerateRope() { // Get the reference of the previous link Rigidbody2D previousRB = hook; for (int i = 0; i < links; i++) { // Create links GameObject link = Instantiate(linkPrefab, transform); // Add reference to the HingeJoint2D for the new link HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); // Connect the current link with the previous link joint.connectedBody = previousRB; if (i < links - 1) { // Set the new previous link previousRB = link.GetComponent <Rigidbody2D>(); } else { // Call the ConnectRopeEnd() from Weight class weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
void GenerateRope() { Rigidbody2D previousRB = hook; for (int i = 0; i < links; i++) { GameObject link = Instantiate(linkPrefab, transform);; /* if (i == 0) * { * link = Instantiate(second, transform); * } * else * { * link = Instantiate(third, transform); * } */ HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; if (i < links - 1) { previousRB = link.GetComponent <Rigidbody2D>(); } else { weigth.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
void GenerateRope() { //Para comenzar la referencia necesitamos un primer elemento en escena Hook Rigidbody2D previousRB = hook; //instanciamos el numero de links que vamos a pintar for (int i = 0; i < links; i++) { //Instanciamos cada uno de los links a partir del padre GameObject link = Instantiate(linkPrefab, transform); //Creamos los elementos que estaran enlazados a Hook HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; if (i < links - 1) { previousRB = link.GetComponent <Rigidbody2D>(); } else { //En el ultimo elemento creamos la conexión al peso //Mandamos el link al ultimo elemento creado weigth.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
private void GenerateRope() { Rigidbody2D previousLink = hook.GetComponent <Rigidbody2D>(); for (int i = 0; i < links; i++) { GameObject link = Instantiate(linkPrefab, this.transform); link.GetComponent <HingeJoint2D>().connectedBody = previousLink; if (i < links - 1) { previousLink = link.GetComponent <Rigidbody2D>(); } else { weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
void GenerateRope() { Rigidbody2D previousRB = hook; for (int i = 0; i < links; i++) { GameObject link = Instantiate(linkPrefab, parent.transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; if (i < links - 1) { previousRB = link.GetComponent <Rigidbody2D>(); } else { weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
void GenerateRope() { Rigidbody2D previousRB = chainHook; for (int i = 0; i < chains; i++) { GameObject chain = Instantiate(chainPrefab, transform); HingeJoint2D joint = chain.GetComponent <HingeJoint2D> (); joint.connectedBody = previousRB; if (i < chains - 1) { previousRB = chain.GetComponent <Rigidbody2D> (); } else { weight.ConnectRopeEnd(chain.GetComponent <Rigidbody2D> ()); } } }
void GenerateRope() { GameObject link = null; Rigidbody2D previousRB = hook.GetComponent <Rigidbody2D>(); // Set first previous body to the Hook for (int i = 0; i < links; i++) { link = Instantiate(linkPrefab, transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; // Connect the new link to the previous body. First time will be hook, afterwards is below if (i < links - 1) { previousRB = link.GetComponent <Rigidbody2D>(); // Link we just made is new previous body } else { weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
void GenerateRope() { Rigidbody2D previousRB = hook; GameObject lastPos = hook.transform.gameObject; for (int i = 0; i < links; i++) { GameObject link = Instantiate(pref, transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; joint.GetComponent <Line_Info>().PreviousPoint = lastPos; if (i < links - 1) { lastPos = link.gameObject; previousRB = link.GetComponent <Rigidbody2D>(); } else { weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
//Loop for each link and create it //Tiene que tener un Line Renderer de alguna manera para que quede bien. void GenerateRope() { Rigidbody2D prevRB = hook; for (int i = 0; i < links; i++) { //transform == parents transform. GameObject link = Instantiate(linkPrefab, transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = prevRB; if (i < links - 1) { //Ahora el RB previo al siguiente es el actual prevRB = link.GetComponent <Rigidbody2D>(); } else { //Le paso el RB del último link weight.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }
private void GenerateRopeV3() { Rigidbody2D previousRB = hook1; CalculateNumberOFLinks(); for (int i = 0; i < links; i++) { GameObject link = Instantiate(linkPrefab, transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; joints.Add(link); if (i < links - 1) { previousRB = link.GetComponent <Rigidbody2D>(); } else { hook2.ConnectRopeEnd(link.GetComponent <Rigidbody2D>()); } } }