Search Unity

Question How to input text into grid layout group

Discussion in 'UGUI & TextMesh Pro' started by klosterj, Dec 31, 2022.

  1. klosterj

    klosterj

    Joined:
    Nov 4, 2022
    Posts:
    2
    Hello to anyone reading this, I am extremely new to unity and have been learning as I go. Right now, I'm attempting to make a grid that has a set number of columns but will continuously add/remove rows as data is updated. Most of the elements in each row will be text except the last row will have to be a check box (toggle). I have watched various tutorials and looked around a bit online on how to go about doing such a thing. I've come to the conclusion that a scroll view with a grid layout group and content size fitter inside would be best. Through looking around online I've found how to populate the grid, but only how to populate it with some Gameobject like an image, nothing like a string (or text). Right now I've got my script set up to read a test document I have as input data, which it's doing correctly, my issue is, I don't know how to put text into the grid. How I've been able to insert a prefab image was to have it as a Gameobject prefab, then GameObject newObj with newObj = (GameObject)Instantiate(prefab,transform);
    With this, you can't simply insert Text, or a string instead, it gives error about not implicitly being able to convert from text to GameObject. It also won't let me do something along the lines of
    (UnityEngine.UI.Text)Instanciate(prefab,transform); //with prefab being the text from my test file read
    It gives the error of 'Text.Text()' inaccessible due to its protection level. So, I've been looking around the internet in how to go about doing this, or how to convert Text to a game object, but every search has led to something along the lines of just click the box in unity to add text. That's not what I'm looking for. I'm looking to use c# to add text to a grid layout group.
    Any and all help would be much appreciated. Again, I am very new to unity, so I'm sorry if this is a very low level question to ask.