Trying to draw lines between a group of game objects

Hey guys,

I have an empty game object with a script attached. The purpose of the script is to create a series of lines linking a series of game objects together.

In the script, I have a game object variable called lineGo to get access to a prefab of an empty with a line renderer component. I have a GameObject array for the game objects I’m drawing lines between, another array of transforms of the same game objects, and a Vector2 array to designate which of those transforms share a line.

This is the code:

public GameObject lineGO;

    public GameObject [] nodes;
    public Transform[] nodeTransforms;
    public Vector2[] nodeID;

	void Start () 

        for (int i = 0; i < nodeID.Length; i++)
            GameObject line = Instantiate(lineGO);

            LineRenderer lr = GetComponentInChildren <LineRenderer>();
            lr.SetPosition(0, new Vector3(nodeTransforms[(int)nodeID<em>.x].position.x, nodeTransforms[(int)nodeID_.x].position.y, nodeTransforms[(int)nodeID*.x].position.z));*_</em>

lr.SetPosition(1, new Vector3(nodeTransforms[(int)nodeID.y].position.x, nodeTransforms[(int)nodeID_.y].position.y, nodeTransforms[(int)nodeID*.y].position.z));

What’s supposed to happen is that an instance of the prefab is instantiated, it is parented to the empty game object that has this script, a reference to its LineRenderer is cached, and then positions 0 and 1 of the line are set to the specified transforms in the array nodeTransforms, using the x and y float values(casted as ints) in the nodeID array as the ID.
The result I’m getting is weird. The number of lines created is correct, however, the positions I’ve tried to assign are only set on the last one, with the previous ones retaining their default prefab settings.
I can’t figure out what I’m doing wrong. Does anyone see it?

Your GetComponentInChildren is implicit run on your GameObject. Try to do line.GetComponent…