Foreach equivalent function in Unity javascript

I'm creating charged particle simulator in Unity3D and need to apply a function to each object within an array.

The array is defined as

var mcp = new Array(GameObject.FindGameObjectsWithTag("MovingChargedParticle"));

My current function to affect each object within the array is:

function applyMagneticForce(particle1, particle2){

    for (MovingChargedParticle mcp in mcp){

    var NewForce :;

    var distance=Vector3.Distance(particle1.transform.position, particle2.transform.position);
    var force=1000 * cp.charge * mcp.charge / Mathf.Pow (distance, 2);

    NewForce += force * distance * cycleinterval;    


For now, cp.charge and mcp.charge are placeholders for calling a public var on other objects..something else I haven't figured out.


Something like this:

var objects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];

for(var item : GameObject in objects)
    print (item.transform.position);

Need Your Help

print_r() and mail() in PHP outputs something different, why?

php magic-quotes

I have a html form where visitors can fill and send me some information, as an e-mail. It sends like this:

How to add a UIPanGestureRecognizer programmatically

xcode uigesturerecognizer

In my app, you can touch the screen and an editable UITextField appears on the screen. I want to be able to move these newly added UITextFields around the screen. I would also like to add a rotation