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[i] = 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[i]);
}
}
}
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
how can I separate each array item with a line so it would look like this:
Answer by fafase · Jul 01, 2016 at 09:24 PM
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.