Code that adds an object to the scroll rect during runtime.

I’ve been stuck on this a while. I’ve created an array that stores the values that the user inputs in the input box. When the user finishes writing, I want to add a UI element into the scrollrect that shows the user’s input. The original input box should remain, but I need the UI elements with what the user has inputted to be shown below it. This is to create a list. Thanks in advance.

Preparation:

  • Add a Content Size Fitter to the object linked as “Content” in the scroll rect.
  • Create a prefab of an object with a text component attached.

Creation:

  • Instantiate the prefab (you either need a reference to the prefab or place it in the Resources folder and load it on runtime)
  • set the text of the text component of the instantiated object to the text of the input field
  • set the parent of the instantiated object’s transform to the content of the scroll rect

Hmm… the prefab doesn’t seem to be appearing…

Please show me the code you have and check in the hierachy if the object is there somewhere…

2962780--219981--SetScrollRect1.gif

IEnumerator SetScrollRect()
{
yield return new WaitForEndOfFrame();
//public ScrollRect _sRect;//Drag assignment
_sRect.verticalNormalizedPosition = 0;
yield return null;
}

2962780–219980–Test_SetScrollRect.zip (35.8 KB)

trying to do the same exact thing, can u please help.