unity – How can I scroll/animate up lines reading from a string to ui text?


This is the reading lines code :

if (primaryTarget != null)
            {
                var lines = primaryTarget.description.Split('n');
                text.text = "Item found: " + primaryTarget.description;
            }
            else
            {
                text.text = "";
            }

And this is the script of the description :
The script is attached to each interactable target(item) :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class InteractableItem : MonoBehaviour
{
    public enum InteractableMode // your custom enumeration
    {
        Description,
        Action
    };
 
    public InteractableMode interactableMode = InteractableMode.Description;
 
    public float distance;
 
    private bool action = true;
 
    (TextArea(1, 10))
    public string description = "";
 
    public void ActionOnItem()
    {
        if(interactableMode == InteractableMode.Action && distance <= 5f && action == true)
        {
 
 
            action = false;
        }
    }
}

Depending on the amount of text in the string I want to show it in the ui Text.
If there is one line then just show the text or even if there are two lines.
but if there is a lot of text then split the lines and scroll the lines smooth up so the first line will be disappear or pushed up and bottom lines will come up.

In the screenshot you can see on the left the text that show in the ui text on the right the text of the description. The ui text can’t show all the text and I don’t want the text to overlap other ui’s or objects so the idea is to make the text slowly smooth scrolling up.

Ui text and string text