I am trying to make a script that will add and edit hinge joints to every object in the scene with the tag “force”. I have rewritten this script multiple times, and now it has stopped working completely. Here is the code-
var forces : GameObject[];
function Update () {
forces = GameObject.FindGameObjectsWithTag("force");
if(Input.GetKeyDown("l")) {
Gotoedit ();
}
}
function Gotoedit () {
for(var i = 0; !i == forces.length; i++){
GameObject.FindGameObjectWithTag("fuse").AddComponent(Rigidbody);
forces*.AddComponent(Rigidbody);*
_ forces*.AddComponent(HingeJoint);_
_ forces.GetComponent(HingeJoint).connectedBody = GameObject.FindGameObjectWithTag(“fuse”).rigidbody;
forces.GetComponent(HingeJoint).spring.damper = Mathf.Infinity;
}
}*
I moved all the forces statements to the function Update (), and them it worked fine with one GameObject, so I know it’t not the AddComponent/GetComponent. I tried adding a debug in the Gotoedit, so I know that it is being called when I press the L key. This leaves the FOR statement, which i’m assuming is the problem. I’m fairly new to FOR statements (not javascript), so I came here to get advice. Does anyone have ideas?
*Javascript only, duh_
*Thanks!