separate the items of an array with lines

In my project I have a game object named “Grandpa” who has multiple children. I assigned Grandpa the following script.

using UnityEngine;
using System.Collections;

public class linechild : MonoBehaviour
{
    public string[] kids;
    public GameObject Grandpa;
  
    void Start()
    {
        Grandpa = GameObject.Find("Grandpa");
        kids = new string[Grandpa.transform.childCount];
    }

    void OnGUI()
    {

        for (int i = 0; i < Grandpa.transform.childCount; i++)
        {
            kids *= Grandpa.transform.GetChild(i).name;*

//Creates a GUI.Label that increments the Y position down for every increment of i
GUI.Label(new Rect(100, 100 + (i * 30), 200, 20), kids*);*
}
}
}
The script stores all of the children of “Grandpa” in an array and displays their names to the screen using GUI.Label. That looks like this
[73324-array-output-no-line.jpg|73324]_
how can I separate each array item with a line so it would look like this:
_
[73325-array-output-with-line.jpg*|73325]*
_*
_*

1 Answer

1

Add an image UI object that you make thin and long like a line.
You can make it a prefab and instantiate in start so that if you have 5 or 10 children it will automatically add it

for(int i =0 ; i < length; i++)
{
     // Add name text 
     if(i == 0 || i == length - 1){ // ignore first and last
             continue;
     }
     // Add name line
}

thanks for the simple answer, this will definitely work! however a UI image will only be visible within a canvas. At least to my knowledge. If I instantiate the image it will do so outside of the canvas rendering them invisible.

I see is the spawn function much different results wise than what I have here? also yes I guess I meant the projectile I have the enemy prefab under the projectile setting it is spawning them but not exactly how I want